Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5c0e9ec

Browse files
authored
Create Day-12_Group_Anagrams.py
1 parent f7388da commit 5c0e9ec

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
3+
d = {}
4+
sor = [''.join(sorted(list(x))) for x in strs]
5+
6+
for i,v in enumerate(sor):
7+
if v not in d:
8+
d[v] = [strs[i]]
9+
else:
10+
d[v].append(strs[i])
11+
12+
13+
return (list(d.values()))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /