You are viewing a single comment's thread. Return to all comments →
My solution is very similar to yours, but most of the test cases have failed. can you tell me why?
public static int numberNeeded(String first, String second) { int numberNeeded = 0; Map<Character, Integer> count = new HashMap<>(); for(char c : first.toCharArray()){ if(count.containsKey(c)) count.put(c, count.get(c)+1); else count.put(c, 1); } for(char c : second.toCharArray()){ if(count.containsKey(c)) count.put(c, count.get(c)-1); else count.put(c, 1); } for(int value: count.values()){ if(value != 0){ numberNeeded++; } } return numberNeeded; }
Seems like cookies are disabled on this browser, please enable them to open this website
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →
My solution is very similar to yours, but most of the test cases have failed. can you tell me why?