-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path383. Ransom Note
31 lines (30 loc) · 906 Bytes
/
383. Ransom Note
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
class Solution:
def canConstruct(self, ransomNote, magazine):
"""
:type ransomNote: str
:type magazine: str
:rtype: bool
"""
# print(ransomNote, magazine)
dic_ran = {}
dic_mag = {}
for i in range(len(ransomNote)):
if ransomNote[i] in dic_ran:
dic_ran[ransomNote[i]] += 1
else:
dic_ran[ransomNote[i]] = 1
for j in range(len(magazine)):
if magazine[j] in dic_mag:
dic_mag[magazine[j]] += 1
else:
dic_mag[magazine[j]] = 1
# print(dic_ran)
# print(dic_mag)
res = True
position = 0
for item in dic_ran.keys():
if item not in dic_mag or dic_ran[item] > dic_mag[item]:
return False
return True
s = Solution()
print(s.canConstruct('', 's'))