forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lemonade Change.cpp
48 lines (44 loc) · 1.12 KB
/
Lemonade Change.cpp
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
class Solution {
public:
bool lemonadeChange(vector<int>& bills) {
unordered_map<int, int> m;
int change = 0;
for(int i = 0 ; i < bills.size(); i++)
{
m[bills[i]]++;
if(bills[i] > 5)
{
change = bills[i] - 5;
if(change == 5)
{
if(m[5] > 0)
{
m[5]--;
}
else
{
return false;
}
}
//change = 10
else
{
if(m[10] > 0 and m[5] > 0)
{
m[10]--;
m[5]--;
}
else if(m[5] >= 3)
{
m[5] -= 3;
}
else
{
return false;
}
}
}
}
return true;
}
};