-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsameProbLeet.py
More file actions
36 lines (32 loc) · 969 Bytes
/
sameProbLeet.py
File metadata and controls
36 lines (32 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution(object):
def canConstruct(self, ransomNote, magazine):
"""
:type ransomNote: str
:type magazine: str
:rtype: bool
"""
# 100 pass - Iteration
magazine = list(magazine)
for char in ransomNote:
if char in magazine:
#print char, magazine
del magazine[magazine.index(char)]
else:
return False
return True
"""
# 100 pass - Dictionary method
counts = {}
for char in magazine:
if char not in counts:
counts[char] = 0
counts[char] += 1
for char in set(ransomNote):
if char not in counts.keys():
return False
if ransomNote.count(char) <= counts[char]:
pass
else:
return False
return True
"""