49. Group Anagrams python

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`
    原文作者:oo上海
    原文地址: https://www.jianshu.com/p/751f920b203d
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞