-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution860.cs
53 lines (48 loc) · 1.08 KB
/
Solution860.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution860
{
/// <summary>
/// 860. Lemonade Change - Easy
/// <a href="https://leetcode.com/problems/lemonade-change">See the problem</a>
/// </summary>
public bool LemonadeChange(int[] bills)
{
int five = 0;
int ten = 0;
foreach (int bill in bills)
{
if (bill == 5)
{
five++;
}
else if (bill == 10)
{
if (five == 0)
{
return false;
}
five--;
ten++;
}
else
{
if (ten > 0 && five > 0)
{
ten--;
five--;
}
else if (five >= 3)
{
five -= 3;
}
else
{
return false;
}
}
}
return true;
}
}