You are viewing a single comment's thread. Return to all comments →
Java
public static int anagram(String s) { if (s.length() % 2 == 0) { String s1 = s.substring(0, s.length() / 2); String s2 = s.substring(s.length() / 2); for (int i = 0; i < s1.length();) { if (s2.indexOf(s1.charAt(i)) == -1) { i++; } else { String toRemove = String.valueOf(s1.charAt(i)); s1 = s1.replaceFirst(toRemove, ""); s2 = s2.replaceFirst(toRemove, ""); } } return s1.length(); } return -1; }
Seems like cookies are disabled on this browser, please enable them to open this website
Anagram
You are viewing a single comment's thread. Return to all comments →
Java