Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created January 26, 2018 14:10
Show Gist options
  • Save s4553711/5462c514996ce932e4f4f00607ac20c3 to your computer and use it in GitHub Desktop.
Save s4553711/5462c514996ce932e4f4f00607ac20c3 to your computer and use it in GitHub Desktop.
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
unordered_map<char, int> res(26);
for(int i = 0; i < magazine.size(); i++)
++res[magazine[i]];
for(int j = 0; j < ransomNote.size(); j++)
if (--res[ransomNote[j]] < 0) return false;
return true;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment