Simple O(n) C++ solution


  • 0
    Q
    bool isAnagram(string s, string t) {
        if(s.size()!=t.size()) return false;
        char times[26]={0}, *ptr=&times[0]-'a';
        for(auto v: s) ++ptr[v];
        for(auto v: t) --ptr[v];
        for(ptr=&times[0];ptr!=&times[26];++ptr)
            if(*ptr) return false;
        return true;
    }

Log in to reply
 

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