Java Anagrams

  • + 1 comment

    My solution. I don't use class Arrays from java.util.Arrays

    static boolean isAnagram(String a, String b) {
            // Complete the function
            char[] aa = a.toLowerCase().toCharArray();
            char[] bb = b.toLowerCase().toCharArray();                      
            
            if (aa.length != bb.length)
                return false;
            
            for (int i = 0; i < aa.length; i++){
                char s1 = aa[i];
                char s2 = bb[i];
                int fs1 = 0;
                int fs2 = 0;
                
                for (int j = 0; j < aa.length; j++){
                    if (aa[j] == s1)
                        fs1++;
                    if (bb[j] == s1)
                        fs2++;
                }
                if (fs1 != fs2)
                    return false;
            }
            
            return 
                true;
        }