49. Group Anagrams python
题目:
https://leetcode.com/problems/anagrams/
难度 : Medium
我又来使用我的取巧神奇python大法
“class Solution(object):
def groupAnagrams(self, strs):
“””
:type strs: List[str]
:rtype: List[List[str]]
“””
mapx = {}
for str1 in strs:
key = self.sortedWord(str1)
if key in mapx:
mapx[key].append(str1)
else:
mapx[key] = [str1]
return list(mapx.values())
def sortedWord(self,s):
"""
:type s: str
:type t: str
:rtype: bool
"""
sList = sorted(list(s))
str1 = ''.join(sList)
return str1`