Skip to content

Commit f242ef7

Browse files
committed
leetcode.com 383. Ransom Note
문제 링크: https://leetcode.com/problems/ransom-note
1 parent 57b9c90 commit f242ef7

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

leetcode.com 383. Ransom Note/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
3+
left, right = list(ransomNote), list(magazine)
4+
5+
for c in left:
6+
try:
7+
idx = right.index(c)
8+
right.pop(idx)
9+
except ValueError:
10+
return False
11+
12+
return True
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from unittest import TestCase
2+
from main import Solution
3+
4+
class TestSolution(TestCase):
5+
def test1_can_construct(self):
6+
sln = Solution()
7+
self.assertEqual(False, sln.canConstruct('a', 'b'))
8+
9+
def test2_can_construct(self):
10+
sln = Solution()
11+
self.assertEqual(False, sln.canConstruct('aa', 'ab'))
12+
13+
def test3_can_construct(self):
14+
sln = Solution()
15+
self.assertEqual(True, sln.canConstruct('aa', 'aab'))

0 commit comments

Comments
 (0)