Skip to content

Commit 499d2af

Browse files
author
涛 陈
committed
Update 0860.柠檬水找零,添加C#
1 parent 4f2b2b2 commit 499d2af

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

problems/0860.柠檬水找零.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,46 @@ object Solution {
397397
}
398398
}
399399
```
400+
### C#
401+
```csharp
402+
public class Solution
403+
{
404+
public bool LemonadeChange(int[] bills)
405+
{
406+
int five = 0, ten = 0, twenty = 0;
407+
foreach (var bill in bills)
408+
{
409+
if (bill == 5) five++;
410+
if (bill == 10)
411+
{
412+
if (five == 0) return false;
413+
five--;
414+
ten++;
415+
}
416+
if (bill == 20)
417+
{
418+
if (ten > 0 && five > 0)
419+
{
420+
ten--;
421+
five--;
422+
twenty++;
423+
}
424+
else if (five >= 3)
425+
{
426+
five -= 3;
427+
twenty++;
428+
}
429+
else
430+
{
431+
return false;
432+
}
433+
434+
}
435+
}
436+
return true;
437+
}
438+
}
439+
```
400440

401441

402442
<p align="center">

0 commit comments

Comments
 (0)