From 09835e74442c5dfdd118e13ffc43c06da5e419d7 Mon Sep 17 00:00:00 2001 From: to_Geek Date: Fri, 10 Nov 2023 22:00:29 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Update=200383.=E8=B5=8E=E9=87=91?= =?UTF-8?q?=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