Strings: Making Anagrams

  • + 2 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;
    }