diff --git a/problems/0242.有效的字母异位词.md b/problems/0242.有效的字母异位词.md index ba942f70..c3e73730 100644 --- a/problems/0242.有效的字母异位词.md +++ b/problems/0242.有效的字母异位词.md @@ -130,7 +130,27 @@ class Solution: return True ``` +Python写法二: + +```python +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + from collections import defaultdict + + s_dict=defaultdict(int) + t_dict=defaultdict(int) + + for x in s: + s_dict[x]+=1 + + for x in t: + t_dict[x]+=1 + + return s_dict==t_dict +``` + Go: + ```go func isAnagram(s string, t string) bool { if len(s)!=len(t){