Skip to content

Commit 0434c7c

Browse files
Add files via upload
1 parent a232235 commit 0434c7c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Group Anagrams/Group_Anagrams.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# 第一种思路,使用字典
2+
# 120ms 97.19%
3+
class Solution:
4+
def groupAnagrams(self, strs):
5+
"""
6+
:type strs: List[str]
7+
:rtype: List[List[str]]
8+
"""
9+
dicts = {}
10+
for letters in strs:
11+
temp = ''.join(sorted(letters))
12+
if temp not in dicts:
13+
dicts[temp] = [letters]
14+
else:
15+
dicts[temp].append(letters)
16+
return [value for value in dicts.values()]

0 commit comments

Comments
 (0)