From 3e506df04426ca8937f09f7a8e9ca9955d0d1c7e Mon Sep 17 00:00:00 2001 From: borninfreedom Date: Sun, 13 Jun 2021 10:56:21 +0800 Subject: [PATCH 1/3] =?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){ From 0d3b8de51227c0c55ace89aa249e0a25377a62be Mon Sep 17 00:00:00 2001 From: borninfreedom Date: Sun, 13 Jun 2021 10:58:05 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0242.有效的字母异位词.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/problems/0242.有效的字母异位词.md b/problems/0242.有效的字母异位词.md index c3e73730..1956253a 100644 --- a/problems/0242.有效的字母异位词.md +++ b/problems/0242.有效的字母异位词.md @@ -137,16 +137,16 @@ class Solution: def isAnagram(self, s: str, t: str) -> bool: from collections import defaultdict - s_dict=defaultdict(int) - t_dict=defaultdict(int) + s_dict = defaultdict(int) + t_dict = defaultdict(int) for x in s: - s_dict[x]+=1 + s_dict[x] += 1 for x in t: - t_dict[x]+=1 + t_dict[x] += 1 - return s_dict==t_dict + return s_dict == t_dict ``` Go: From 4993e9ff6bfab26473eeb9b99f07ae544f0afca3 Mon Sep 17 00:00:00 2001 From: borninfreedom Date: Sun, 13 Jun 2021 11:14:21 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=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=E6=B7=BB=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0242.有效的字母异位词.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/0242.有效的字母异位词.md b/problems/0242.有效的字母异位词.md index 1956253a..93bba44c 100644 --- a/problems/0242.有效的字母异位词.md +++ b/problems/0242.有效的字母异位词.md @@ -130,7 +130,7 @@ class Solution: return True ``` -Python写法二: +Python写法二(没有使用数组作为哈希表,只是介绍defaultdict这样一种解题思路): ```python class Solution: