Skip to content

Commit 8588591

Browse files
committed
Leetcode accepted
1 parent e8d5de5 commit 8588591

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Group Anagrams
2+
# https://leetcode.com/problems/group-anagrams/
3+
4+
class Solution(object):
5+
def groupAnagrams(self, strs):
6+
bucket = {}
7+
# sort all strings alphabetically and add to hash
8+
for s in strs:
9+
sortedString = "".join(sorted(s))
10+
if (sortedString not in bucket):
11+
bucket[sortedString] = []
12+
bucket[sortedString].append(s)
13+
# create list from the bucket hash
14+
answerList = []
15+
for sortedString in bucket:
16+
answerList.append(bucket[sortedString])
17+
return answerList
18+
"""
19+
:type strs: List[str]
20+
:rtype: List[List[str]]
21+
"""
22+

Blind 75/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,10 @@
234234
<p><b>Approach</b>: Used hash table.
235235
</p>
236236
</li>
237-
<li>Group Anagrams</li>
237+
<li><a href="Programs/Group Anagrams.py">Group Anagrams</a>
238+
<p><b>Approach</b>: Sort the strings and store them in hash table.
239+
</p>
240+
</li>
238241
<li>Valid Parentheses</li>
239242
<li>Valid Palindrome</li>
240243
<li>Longest Palindromic Substring</li>

0 commit comments

Comments
 (0)