力扣 49. 字母异位词分组

排序 + hash表

1
2
3
4
5
6
7
8
9
10
def groupAnagrams(strs):
dic = {}
for s in strs:
cur = "".join(sorted(s))
if cur in dic.keys():
dic[cur].append(s)
else:
dic[cur] = [s]

return list(dic.values())
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022 eightyninth
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信