383. 赎金信
小于 1 分钟
383. 赎金信简单
解法思路:通过数组计数,模拟 hash
class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
int[] cnt = new int[26];
for(char c : magazine.toCharArray()){
cnt[c-'a']++;
}
for(char c: ransomNote.toCharArray()){
if(--cnt[c-'a'] < 0){
return false;
}
}
return true;
}
}
Powered by Waline v2.15.5