pass 383 easy
This commit is contained in:
parent
713e1c9cea
commit
8d5f40d02b
27
383-240524-pass/main.py
Normal file
27
383-240524-pass/main.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
class Solution:
|
||||||
|
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
|
||||||
|
ran_dic = {}
|
||||||
|
mag_dic = {}
|
||||||
|
for l in ransomNote:
|
||||||
|
if l not in ran_dic:
|
||||||
|
ran_dic[l] = 1
|
||||||
|
else:
|
||||||
|
ran_dic[l] += 1
|
||||||
|
for l in magazine:
|
||||||
|
if l not in mag_dic:
|
||||||
|
mag_dic[l] = 1
|
||||||
|
else:
|
||||||
|
mag_dic[l] += 1
|
||||||
|
print(ran_dic)
|
||||||
|
print(mag_dic)
|
||||||
|
for key in ran_dic:
|
||||||
|
if key not in mag_dic:
|
||||||
|
return False
|
||||||
|
if ran_dic[key] > mag_dic[key]:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
sol = Solution()
|
||||||
|
print(sol.canConstruct("a", "b"))
|
||||||
|
print(sol.canConstruct("aa", "ab"))
|
||||||
|
print(sol.canConstruct("aa", "aab"))
|
Loading…
Reference in New Issue
Block a user