Created
January 26, 2018 14:10
-
-
Save s4553711/5462c514996ce932e4f4f00607ac20c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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