You are viewing a single comment's thread. Return to all comments →
public class Solution { static boolean isAnagram(String a, String b) { if (a.length() != b.length()) return false; if (sortAsc(a).compareTo(sortAsc(b)) != 0) return false; return true; } // Bubble Sort Algorithm public static String sortAsc(String value){ char[] c = value.toLowerCase().toCharArray(); for (int i=0;i<c.length-1;i++){ for (int j=0;j<c.length-1-i;j++){ if(c[j]> c[j+1]){ char temp = c[j]; c[j] = c[j+1]; c[j+1] = temp; } } } return new String(c); }
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 →