简单计数:
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
vector<int> exist(26, 0);
for(const auto &c : magazine) ++exist[c - 'a'];
for(const auto &c : ransomNote){
if(exist[c - 'a'] == 0) return false;
else --exist[c - 'a'];
}
return true;
}
};