5 lines C++ solution


  • 2
    S
    class Solution {
    public:
        bool isAnagram(string s, string t) {
            vector<int> count(26);
            for (auto c : s) count[c - 'a']++;
            for (auto c : t) count[c - 'a']--;
            for (auto i : count) if (i) return false;
            return true;
        }
    };

Log in to reply
 

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