leetcode/383-240524-pass/main.py
2024-05-24 23:28:39 +02:00

27 lines
791 B
Python

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"))