Simple C++ Solution

  • 0
        bool isAnagram(string s, string t) {
            unordered_map<char, int> map;
            for (char c : s) map[c]++;
            for (char c : t) {
                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.