From 7f53e73e544dd650bc7c8efb321fbaafe775fbe3 Mon Sep 17 00:00:00 2001 From: Zeeland <287017217@qq.com> Date: Sat, 5 Nov 2022 18:22:51 +0800 Subject: [PATCH] =?UTF-8?q?Update=200242.=E6=9C=89=E6=95=88=E7=9A=84?= =?UTF-8?q?=E5=AD=97=E6=AF=8D=E5=BC=82=E4=BD=8D=E8=AF=8D.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加新的python题解方法 --- problems/0242.有效的字母异位词.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/problems/0242.有效的字母异位词.md b/problems/0242.有效的字母异位词.md index f8ebc545..93ab90a2 100644 --- a/problems/0242.有效的字母异位词.md +++ b/problems/0242.有效的字母异位词.md @@ -154,6 +154,16 @@ class Solution: return s_dict == t_dict ``` +Python写法三(没有使用数组作为哈希表,只是介绍Counter这种更方便的解题思路): + +```python +class Solution(object): + def isAnagram(self, s: str, t: str) -> bool: + from collections import Counter + a_count = Counter(s) + b_count = Counter(t) + return a_count == b_count +``` Go: