You are viewing a single comment's thread. Return to all comments →
This simple Java code works in all cases
if (a.length() != b.length()) { return false; } a = a.toLowerCase(); b = b.toLowerCase(); int sum = 0; for (char c = 'a'; c <= 'z'; c++) { for (int i=0; i<a.length(); i++) { if (a.charAt(i) == c) { sum++; } if (b.charAt(i) == c) { sum--; } } if (sum != 0) { 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 →
This simple Java code works in all cases