class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
// put magazine in hashmap, key: character, value: count
// check each character in ransomNote and minus count
// If unvalid situation, return false
// return true if completely iterates ransomNote
int magazineCharToCount[26];
memset(magazineCharToCount, 0, sizeof(magazineCharToCount));
for(char c : magazine){
magazineCharToCount[c - 'a']++;
}
for(char c : ransomNote){
int idx = c - 'a';
if(magazineCharToCount[idx] == 0){
return false;
}
magazineCharToCount[idx]--;
}
return true;
}
};