0%

代码随想录第十八天

哈希表-赎金信

题目链接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
int record[26] = {0};
for(int i = 0; i < magazine.length(); i++){
record[magazine[i]-'a']++;
}
for(int j = 0; j < ransomNote.length(); j++){
record[ransomNote[j]-'a']--;
if(record[ransomNote[j]-'a'] < 0)
return false;
}
return true;
}
};