383.赎金信
一、直方图法
class Solution:
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
cnt = [0] * 26
for c in ransomNote:
cnt[ord(c) - ord('a')] += 1
for c in magazine:
cnt[ord(c) - ord('a')] -= 1
for num in cnt:
if num > 0:
return False
return True最后更新于