题目描述:
首刷自解:
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
if (magazine.size() < ransomNote.size()) return false;
unordered_map<char, int> buckets;
for (const auto& iter1 : magazine)
++buckets[iter1];
for (const auto& iter2 : ransomNote)
{
unordered_map<char, int>::const_iterator ret = buckets.find(iter2);
if (ret == buckets.end() || !ret->second)
return false;
else
--buckets[iter2];
}
return true;
}
};