为了不在赎金信中暴露字迹,从杂志上搜索各个需要的字母,组成单词来表达意思。
给你一个赎金信 (ransomNote) 字符串和一个杂志(magazine)字符串,判断 ransomNote 能不能由 magazines 里面的字符构成。
如果可以构成,返回 true ;否则返回 false 。
magazine 中的每个字符只能在 ransomNote 中使用一次。
连续四天easy了,我不好说,大的要来了
python天下第一,说了114514次了,counter真的是真神,Java?狗都不用!
class Solution:
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
a = Counter(ransomNote)
b = Counter(magazine)
return (a & b) == a