Solve it with java 8 stream pattern

  • 0

    Nothing fancy comparing to python or ruby, but if you prefer java and hate to write a lot of for loops:

        public List<List<String>> groupAnagrams(String[] strs) {
            return Arrays.asList(strs).stream()
                    .collect(Collectors.groupingBy(str -> {
                        char[] patt = str.toCharArray();
                        return String.valueOf(patt);

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.