From 3e506df04426ca8937f09f7a8e9ca9955d0d1c7e Mon Sep 17 00:00:00 2001 From: borninfreedom Date: Sun, 13 Jun 2021 10:56:21 +0800 Subject: [PATCH] =?UTF-8?q?update=E6=9C=89=E6=95=88=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E6=AF=8D=E5=BC=82=E4=BD=8D=E8=AF=8D=EF=BC=8Cpython=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=9B=B4pythonic=E7=9A=84?= =?UTF-8?q?=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0242.有效的字母异位词.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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){