Skip to content

Commit 9812192

Browse files
committed
add a type-2 solution of python
add a type-2 solution of python
1 parent 7d5bba4 commit 9812192

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

zh-hans/string/anagrams.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,28 @@ private:
121121
122122
**leetcode 上此题的 signature 已经更新,需要将 anagrams 按组输出,稍微麻烦一点点。**
123123
124+
### Python lintcode
125+
126+
```python
127+
class Solution:
128+
# @param strs: A list of strings
129+
# @return: A list of strings
130+
# @return: A list of strings
131+
def anagrams(self, strs):
132+
strDict={}
133+
result=[]
134+
for string in strs:
135+
if "".join(sorted(string)) not in strDict.keys():
136+
strDict["".join(sorted(string))] = 1
137+
else:
138+
strDict["".join(sorted(string))] += 1
139+
for string in strs:
140+
if strDict["".join(sorted(string))] >1:
141+
result.append(string)
142+
return result
143+
```
144+
145+
124146
### C++ - lintcode
125147

126148
```c++

0 commit comments

Comments
 (0)