天天看点

[CareerCup] 11.2 Sort Anagrams Array 异位词数组排序

11.2 Write a method to sort an array of strings so that all the anagrams are next to each other.

解法一:

另一种解法较为复杂一些,用到了哈希表来建立排序后的字符串和其所有的异位词集合的映射,最后在按集合填充原数组,参见代码如下:

解法二: