We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8ee69dd commit 570b682Copy full SHA for 570b682
Kangli/Strings/groupAnagrams.py
@@ -0,0 +1,9 @@
1
+class Solution(object):
2
+ def groupAnagrams(self, strs):
3
+ d = collections.defaultdict(list)
4
+ for s in strs:
5
+ d["".join(sorted(s))].append(s)
6
+ return [ group for group in d.values() ]
7
+
8
+# use a hash, sort each string and use it as a key. Append unsorted string to list of values.
9
+# return all values
0 commit comments