From 09835e74442c5dfdd118e13ffc43c06da5e419d7 Mon Sep 17 00:00:00 2001 From: to_Geek Date: Fri, 10 Nov 2023 22:00:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=93=9D=20Update=200383.=E8=B5=8E?= =?UTF-8?q?=E9=87=91=E4=BF=A1.md=20with=20python3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0383.赎金信.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/problems/0383.赎金信.md b/problems/0383.赎金信.md index 3de48ce3..b800c232 100644 --- a/problems/0383.赎金信.md +++ b/problems/0383.赎金信.md @@ -214,6 +214,19 @@ class Solution: return all(ransomNote.count(c) <= magazine.count(c) for c in set(ransomNote)) ``` +(版本六)使用count(简单易懂) + +```python3 +class Solution: + def canConstruct(self, ransomNote: str, magazine: str) -> bool: + for char in ransomNote: + if char in magazine and ransomNote.count(char) <= magazine.count(char): + continue + else: + return False + return True +``` + ### Go: ```go From ce2ffd073c20fa72c07df54b4566d285172276c4 Mon Sep 17 00:00:00 2001 From: to_Geek Date: Sun, 12 Nov 2023 23:44:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9D=20Update=200344.=E5=8F=8D?= =?UTF-8?q?=E8=BD=AC=E5=AD=97=E7=AC=A6=E4=B8=B2.md=20with=20python3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0344.反转字符串.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/problems/0344.反转字符串.md b/problems/0344.反转字符串.md index 8a4fed45..44184c53 100644 --- a/problems/0344.反转字符串.md +++ b/problems/0344.反转字符串.md @@ -250,6 +250,20 @@ class Solution: s[:] = [s[i] for i in range(len(s) - 1, -1, -1)] ``` + +(版本七) 使用reverse() + +```python +class Solution: + def reverseString(self, s: List[str]) -> None: + """ + Do not return anything, modify s in-place instead. + """ + # 原地反转,无返回值 + s.reverse() + +``` + ### Go: ```Go