#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param ransomNote string字符串
# @param magazine string字符串
# @return bool布尔型
#
from collections import Counter
class Solution:
def canConstruct(self , ransomNote: str, magazine: str) -> bool:
# write code here
s = Counter(ransomNote)
t = Counter(magazine)
for c in s.keys():#依次查看s中的元素是否都在t中,且数量正确
if c not in t or s[c]>t[c]:
return False
return True



京公网安备 11010502036488号