c++ unordered_map (O(n + m))


  • 0
    bool canConstruct(string ransomNote, string magazine) {
        unordered_map<char, int> m;
        for (char c : ransomNote) m[c]++;
        for (char c : magazine)
            if (--m[c] <= 0) m.erase(c);
        return m.empty();
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.