Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 312e7d8

Browse files
Merge pull request #394 from borninfreedom/master
update有效的字母异位词,python代码添加了更pythonic的写法
2 parents 2ff875d + 4993e9f commit 312e7d8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎problems/0242.有效的字母异位词.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,27 @@ class Solution:
130130
return True
131131
```
132132

133+
Python写法二(没有使用数组作为哈希表,只是介绍defaultdict这样一种解题思路):
134+
135+
```python
136+
class Solution:
137+
def isAnagram(self, s: str, t: str) -> bool:
138+
from collections import defaultdict
139+
140+
s_dict = defaultdict(int)
141+
t_dict = defaultdict(int)
142+
143+
for x in s:
144+
s_dict[x] += 1
145+
146+
for x in t:
147+
t_dict[x] += 1
148+
149+
return s_dict == t_dict
150+
```
151+
133152
Go:
153+
134154
```go
135155
func isAnagram(s string, t string) bool {
136156
if len(s)!=len(t){

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /