1 2 3 4 5 6 7 8 9 10 11 12 13 14 | class Solution { public: bool canConstruct(string ransomNote, string magazine) { std::unordered_map<char, int> cnt; for (auto c : magazine) cnt[c]++; for (auto c : ransomNote) if (cnt[c] > 0) cnt[c]--; else return false; return true; } }; |