代码随想录:赎金信
同上题
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
//其实就26个字母可以用数组的,懒得改了
unordered_map<char, int> maga;
for (char c : magazine) {
auto it = maga.find(c);
if (it != maga.end()) {
it->second++;
} else {
maga.insert(make_pair(c, 1));
}
}
for (char c : ransomNote) {
auto it = maga.find(c);
if (it != maga.end()) {
if (it->second > 0) {
it->second--;
} else {
return false;
}
} else {
return false;
}
}
return true;
}
};
标签:return,代码,随想录,else,second,赎金,maga
From: https://www.cnblogs.com/huigugu/p/18571102