My short C++code 12ms


  • 3
    X

    class Solution {
    public:
    bool isAnagram(string s, string t) {
    //use 26 array
    if(s.size() != t.size())
    {
    return false;
    }

        int arr[26]={0};
        for(int ii=0; ii<s.size(); ++ii)
        {
            ++arr[s[ii]-'a'];
            --arr[t[ii]-'a'];
        }
        
        for(int ii=0; ii<26; ++ii)
        {
            if(arr[ii] != 0)
            {
                return false;
            }
        }
        return true;
    }
    

    };


Log in to reply
 

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