Skip to content

Commit d81cdf1

Browse files
Merge pull request neetcode-gh#139 from BHARAT0310/patch-1
Update 49-Group-Anagrams.py
2 parents 4189a2c + 1836e5f commit d81cdf1

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

49-Group-Anagrams.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
class Solution:
22
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
3-
ans = collections.defaultdict(list)
4-
3+
hashmap = defaultdict(list)
54
for s in strs:
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()
5+
# keys can be strings, bcz they are immutable.
6+
hashmap[str(sorted(s))].append(s)
7+
return hashmap.values()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy