From ba3c7ec19b6b2ad3f95f35ae55f25b2459d710b3 Mon Sep 17 00:00:00 2001 From: jianghongcheng <35664721+jianghongcheng@users.noreply.github.com> Date: Thu, 1 Jun 2023 01:37:41 -0500 Subject: [PATCH] =?UTF-8?q?Update=200860.=E6=9F=A0=E6=AA=AC=E6=B0=B4?= =?UTF-8?q?=E6=89=BE=E9=9B=B6.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0860.柠檬水找零.md | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/problems/0860.柠檬水找零.md b/problems/0860.柠檬水找零.md index d96e0879..5046df12 100644 --- a/problems/0860.柠檬水找零.md +++ b/problems/0860.柠檬水找零.md @@ -164,24 +164,39 @@ class Solution { ```python class Solution: def lemonadeChange(self, bills: List[int]) -> bool: - five, ten = 0, 0 + five = 0 + ten = 0 + twenty = 0 + for bill in bills: + # 情况一:收到5美元 if bill == 5: five += 1 - elif bill == 10: - if five < 1: return False - five -= 1 + + # 情况二:收到10美元 + if bill == 10: + if five <= 0: + return False ten += 1 - else: - if ten > 0 and five > 0: - ten -= 1 + five -= 1 + + # 情况三:收到20美元 + if bill == 20: + # 先尝试使用10美元和5美元找零 + if five > 0 and ten > 0: five -= 1 - elif five > 2: + ten -= 1 + #twenty += 1 + # 如果无法使用10美元找零,则尝试使用三张5美元找零 + elif five >= 3: five -= 3 + #twenty += 1 else: return False + return True + ``` ### Go