LeetCode 383 赎金信
作者:互联网
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
int record[26] ={0}; //默认值为0
if (magazine.size() < ransomNote.size()) return false;
for(int i = 0; i < magazine.size(); i ++) {
record[magazine[i] - 'a'] ++;
}
for(int i = 0; i < ransomNote.size(); i ++) {
record[ransomNote[i] - 'a'] --;
if (record[ransomNote[i] - 'a'] < 0) return false;
}
return true;
}
};
标签:ransomNote,return,int,record,magazine,383,赎金,LeetCode,size 来源: https://www.cnblogs.com/hjy94wo/p/16659138.html