class Solution { public: bool canConstruct(string ransomNote, string magazine) { int map[26]{ 0 }; for(auto ch : magazine) ++map[ch - 'a']; for(auto ch : ransomNote) --map[ch - 'a']; for(int i = 0; i < 26; ++i) if(map[i] < 0) return false; return true; } };
|