Fast c# solution


  • 0
    E
     public bool IsAnagram(string s, string t) 
    {        
            int[] lookup = new int[26];
            
            int length = s.Length;
            if(length != t.Length) return false;
            
            for(int i = 0; i < length; i++)
            {
                int si = (int)(s[i]-'a');
                int ti = (int)(t[i]-'a');
                lookup[si]++;
                lookup[ti]--;
            }
            
            for(int i =0 ; i< lookup.Length; i++)
            {
                if(lookup[i] != 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.