C++ 12ms / constant space array


  • 3
    N
    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++)
            bit[s[i]-'a']++;
        
        for(int i=0; i<len; i++)
            if(--bit[t[i]-'a'] < 0)
                return false;
                
        return true;
    }

  • 0
    Z

    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.