Friday, February 12, 2016

LeetCode Q49: Group Anagrams

Given an array of strings, group anagrams together.
For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"],
Return:


[
  ["ate", "eat","tea"],
  ["nat","tan"],
  ["bat"]
]


Use sort and hash. The key used in hash is in format C1X1C2X2... where C is a character, X is the number of C showing up in the string.


No comments:

Post a Comment