LeetCode forty-ninth title - letter word grouping ectopic

Group Anagrams

Problem description:

Given a string array, owned by the same string of characters as a class, returns a set of classification

For example:

输入: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”],

Output:

[

[“ate”,“eat”,“tea”],

[ "Night", "tan"],

[“bat”]

]

Explanation:

Result set, the first set of a string of 'a' 't' 'e' composition consisting of, by a second set of 'n' 'a' 't' collection of the third set by the character 'b' 'a' 't' composition

Solution one:

The idea is to build a by the HashMap, wherein the key is the result of our different string of characters in ascending, for example, a first sub-set of example, the first key is the dictionary ordering "aet", values ​​is the result set. " ate "," eat "," tea "

White brush the question of road, please enlighten - - either a late bloomer, or go down the drain

Guess you like

Origin www.cnblogs.com/lalalaczq/p/10985203.html