You are viewing a single comment's thread. Return to all comments →
// Solution without Arrays.sort()
static boolean isAnagram(String a, String b) { // Complete the function char[] arrayA = a.toLowerCase().toCharArray(); char[] arrayB = b.toLowerCase().toCharArray(); if(arrayA.length == arrayB.length){ char temp; //Sort arrayA for(int i = 0; i < arrayA.length; i++){ for(int j = i+1; j < arrayA.length; j++){ if(arrayA[i] > arrayA[j]){ temp = arrayA[i]; arrayA[i] = arrayA[j]; arrayA[j] = temp; } } } //Sort arrayB for(int i = 0; i < arrayB.length; i++){ for(int j = i+1; j < arrayB.length; j++){ if(arrayB[i] > arrayB[j]){ temp = arrayB[i]; arrayB[i] = arrayB[j]; arrayB[j] = temp; } } } //Compare arrayA and arrayB for(int i = 0; i < arrayA.length; i++){ if(arrayA[i] != arrayB[i]){ return false; } } return true; } return false; }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Anagrams
You are viewing a single comment's thread. Return to all comments →
// Solution without Arrays.sort()