6ms Java Solution


  • 1
    public boolean isAnagram(String s, String t) {
            int n = s.length();
            if(n != t.length()) return false;
            int[] alp = new int[26];
            char[] cs = s.toCharArray();
            char[] ct = t.toCharArray();
            for(int i=0; i<n; ++i)
            {
                alp[cs[i]-'a']++;
                alp[ct[i]-'a']--;
            }
            for(int a : alp)
            {
                if(a!=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.