Java Anagrams

  • + 40 comments

    How about my code . It also works fine and is good code with minimum time complexity i think.

    if(a.length() != b.length()) return false;
            int c[] = new int[26], d[] = new int[26] ;
            a = a.toUpperCase();
            b = b.toUpperCase();
            for(int i=0; i<a.length(); i++){
                c[a.charAt(i) - 'A']++;
                d[b.charAt(i) - 'A']++;
            }
            for(int i =0;i<26; i++)
                if(c[i] != d[i] ) return false;
            return true;