C++ solution very elegant and easy to understand


  • 0
    Q
    class Solution {
    public:
        bool isAnagram(string s, string t) {
            if(s.size() != t.size())
                return false;
            vector<int> v(26,0);
            for(auto it:s)
                v[it-'a']++;
            for(auto it:t){
                if(v[it-'a'] == 0)
                    return false;
                v[it - 'a']--;
            }
            return true;
        }
    };
    

Log in to reply
 

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