simple python


  • 0

    def groupAnagrams(self, strs):
    """
    :type strs: List[str]
    :rtype: List[List[str]]
    """
    rst = []
    if len(strs) == 0:
    return rst
    dic_index = 0
    str_dic = {}
    for ele in strs:
    ele_sorted = ''.join(sorted(ele))
    if ele_sorted not in str_dic:
    str_dic[ele_sorted] = dic_index
    dic_index += 1
    list_temp = []
    list_temp.append(ele)
    rst.append(list_temp)
    else:
    rst[str_dic[ele_sorted]].append(ele)
    return rst


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.