C++ 12ms / constant space array

  • 3
    bool isAnagram(string s, string t) {
        if(s.length() != t.length()) return false;
        int bit[26] = {0}, len = s.length();
        for(int i=0; i<len; i++)
        for(int i=0; i<len; i++)
            if(--bit[t[i]-'a'] < 0)
                return false;
        return true;

  • 0

    I coded up a similar one:)

Log in to reply

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