LCR 033. 字母异位词分组
为保证权益,题目请参考 LCR 033. 字母异位词分组(From LeetCode).
解决方案1
Python
python
from typing import List
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
d = dict()
for s in strs:
s2 = "".join(sorted(s))
if s2 not in d:
d[s2] = []
d[s2].append(s)
return list(d.values())
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14