You are viewing a single comment's thread. Return to all comments →
static boolean isAnagram(String a, String b) { String s1=a.toLowerCase(); String s2=b.toLowerCase(); int [] countofs1= new int[26]; int [] countofs2= new int[26]; for(char c:s1.toCharArray()){ countofs1[c-'a']++; } for(char c:s2.toCharArray()){ countofs2[c-'a']++; } for(int i=0;i<26;i++){ if(countofs1[i] != countofs2[i]){ return false; } } return true; }
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 →