Simple C++ Solution


  • 0
    F
        bool isAnagram(string s, string t) {
            unordered_map<char, int> map;
            for (char c : s) map[c]++;
            for (char c : t) {
                map[c]--;
                if (map[c] < 0) return false;
                else if (map[c] == 0) map.erase(c);
            }
            return map.empty();
        }
    

Log in to reply
 

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