Skip to content

Commit

Permalink
Update 0860.柠檬水找零,添加C#
Browse files Browse the repository at this point in the history
  • Loading branch information
涛 陈 committed Jan 3, 2024
1 parent 4f2b2b2 commit 499d2af
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions problems/0860.柠檬水找零.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
```


<p align="center">
Expand Down

0 comments on commit 499d2af

Please sign in to comment.