-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path383.py
More file actions
31 lines (28 loc) · 814 Bytes
/
383.py
File metadata and controls
31 lines (28 loc) · 814 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
import collections
class Solution(object):
def canConstruct(self, ransomNote, magazine):
ransomNotelist = list(ransomNote)
magazinelist = list(magazine)
flag = True
for ran in ransomNotelist:
if ran in magazinelist:
magazinelist.remove(ran)
flag = True
else:
return False
return flag
# method2
# class Solution(object):
# def canConstruct(self, ransomNote, magazine):
# """
# :type ransomNote: str
# :type magazine: str
# :rtype: bool
# """
# cnt = collections.Counter(magazine)
# for letter in ransomNote:
# cnt[letter] -= 1
# if cnt[letter] <0: return False
# return True
test = Solution()
print test.canConstruct("fihjjjjei","hjibagacbhadfaefdjaeaebgi")