Skip to content

Commit 1836e5f

Browse files
authored
Update 49-Group-Anagrams.py
Run time and Memory usage of the above solution is. R.T = 140ms M.U = 18.4MB
1 parent 51bcb14 commit 1836e5f

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