You are viewing a single comment's thread. Return to all comments →
java
if(s.length()%2 > 0) return -1; String s1 = s.substring(0, s.length()/2); String s2 = s.substring(s.length()/2); int count = 0; Map<Character,Integer> map = new HashMap<>(); for(Character c : s1.toCharArray()){ if(map.containsKey(c)){ map.put(c, map.get(c)+1); }else{ map.put(c, 1); } } for(Character c : s2.toCharArray()){ if(map.containsKey(c)) { if (map.get(c) == 1) map.remove(c); else map.put(c, map.get(c)-1); }else{ count++; } } return count; }
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