Strings: Making Anagrams

  • + 0 comments

    Java:

        public static int makeAnagram(String a, String b) {
        int numberOfDeletions = 0;
        for (int i = 0; i < a.length(); i++) {
            String currentCharacter = String.valueOf(a.charAt(i));
            if(b.contains(currentCharacter)){
                b = b.replaceFirst(currentCharacter, "");
            } else {
                ++numberOfDeletions;
            }
        }
        return numberOfDeletions + b.length();
        }