Skip to content

Commit 649197a

Browse files
Solve : Group Anagram 2
1 parent 92240cd commit 649197a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

encode-and-decode-strings/printjin-gmailcom.py

Whitespace-only changes.

group-anagrams/printjin-gmailcom.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ class Solution:
44
def groupAnagrams(self, strs):
55
anagrams = defaultdict(list)
66
for word in strs:
7-
key = ''.join(sorted(word))
8-
anagrams[key].append(word)
7+
count = [0] * 26
8+
for c in word:
9+
count[ord(c) - ord('a')] += 1
10+
anagrams[tuple(count)].append(word)
911
return list(anagrams.values())

0 commit comments

Comments
 (0)