We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8a3d98f commit 8e6c7feCopy full SHA for 8e6c7fe
anagrams.py
@@ -0,0 +1,21 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+class Solution:
4
+ # @param strs: A list of strings
5
+ # @return: A list of strings
6
+ def anagrams(self, strs):
7
+ # write your code here
8
+ ret = []
9
+ word_map = {}
10
+ for word in strs:
11
+ sorted_word = ''.join(sorted(word))
12
+ if sorted_word not in word_map:
13
+ word_map[sorted_word] = {'count':1, 'words':[word]}
14
+ else:
15
+ word_map[sorted_word]['count'] += 1
16
+ word_map[sorted_word]['words'].append(word)
17
+ for key, info in word_map.items():
18
+ if info['count'] > 1:
19
+ for word in info['words']:
20
+ ret.append(word)
21
+ return ret
0 commit comments