Skip to content

Commit

Permalink
Create group-anagrams.py
Browse files Browse the repository at this point in the history
groups words in list by anagram
  • Loading branch information
gabedonnan authored Jan 17, 2023
1 parent 9c7b1c3 commit 26f14ae
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions group-anagrams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
temp = {}
for s in strs:
sort_str = "".join(sorted(s))
if sort_str not in temp:
temp[sort_str] = [s]
else:
temp[sort_str].append(s)
final = []
for t in temp:
final.append(temp[t])
return final

0 comments on commit 26f14ae

Please sign in to comment.