Group Anagrams
Problem: Group Anagrams
We just calculate alphabet of each string and hash it into right alphabet in table.
Code in Python:
class Solution(object):
def groupAnagrams(self, strs):
"""
:type strs: List[str]
:rtype: List[List[str]]
"""
strs.sort()
dict = {}
for string in strs:
key = str(sorted(string))
if key not in dict: dict[key] = [string]
else: dict[key].append(string)
return [value for value in dict.values()]