From 499d2afb618298ddb3e0e4f8d88f6f13284f0d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=9B=20=E9=99=88?= <761050293@qq.com> Date: Wed, 3 Jan 2024 09:21:34 +0800 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=EF=BC=8C=E6=B7=BB=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0860.柠檬水找零.md | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/problems/0860.柠檬水找零.md b/problems/0860.柠檬水找零.md index 50a0c31a..db70112d 100644 --- a/problems/0860.柠檬水找零.md +++ b/problems/0860.柠檬水找零.md @@ -397,6 +397,46 @@ object Solution { } } ``` +### C# +```csharp +public class Solution +{ + public bool LemonadeChange(int[] bills) + { + int five = 0, ten = 0, twenty = 0; + foreach (var bill in bills) + { + if (bill == 5) five++; + if (bill == 10) + { + if (five == 0) return false; + five--; + ten++; + } + if (bill == 20) + { + if (ten > 0 && five > 0) + { + ten--; + five--; + twenty++; + } + else if (five >= 3) + { + five -= 3; + twenty++; + } + else + { + return false; + } + + } + } + return true; + } +} +```