You are viewing a single comment's thread. Return to all comments →
I like your solution. I also modified it slightly to use Java 8 IntStream for summing up the ints the functional way.
public static int numberNeeded(String first, String second) { int [] letters = new int[26]; for(char c : first.toCharArray()){ letters[c-'a']++; } for(char c : second.toCharArray()){ letters[c-'a']--; } return IntStream.of(letters).map( i -> Math.abs(i)).sum(); }
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 →
I like your solution. I also modified it slightly to use Java 8 IntStream for summing up the ints the functional way.