Skip to content

Commit f4f5256

Browse files
authored
Revert "Update 49-Group-Anagrams.py"
1 parent d1c71ec commit f4f5256

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

49-Group-Anagrams.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
class Solution:
22
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
3-
hashmap = defaultdict(list)
3+
ans = collections.defaultdict(list)
4+
45
for s in strs:
5-
# keys can be strings, bcz they are immutable.
6-
hashmap[str(sorted(s))].append(s)
7-
return hashmap.values()
6+
count = [0] * 26
7+
for c in s:
8+
count[ord(c) - ord('a')] += 1
9+
ans[tuple(count)].append(s)
10+
return ans.values()

0 commit comments

Comments
 (0)