Sharing my 12ms C++ solution


  • 1
    T
    class Solution {
    private:
        vector<int> count(string s)
        {
            vector<int> result(26, 0);
            for(int i=0; i<s.length(); i++)
                result[s[i]-'a']++;
            return result;
        }
    public:
        bool isAnagram(string s, string t) {
            vector<int> rs = count(s);
            vector<int> rt = count(t);
            return (rs==rt);
        }
    };

Log in to reply
 

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