Ransom Note

2017/12/9 posted in  leetcode

class Solution {
public:
    bool canConstruct(string ransomNote, string magazine) {
        unordered_map<char, int> map;
        for (int i = 0; i<magazine.length(); i++) {
            map[magazine[i]]++;
        }
        for (int j = 0; j<ransomNote.length(); j++) {
            if(--map[ransomNote[j]]<0) return 0;
        }
        return 1;
    }
};