File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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>
You can’t perform that action at this time.
0 commit comments