mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-11 04:54:51 +08:00
Update 0860.柠檬水找零,添加C#
This commit is contained in:
@ -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">
|
<p align="center">
|
||||||
|
Reference in New Issue
Block a user