题目链接
贪心
class Solution {
public boolean lemonadeChange(int[] bills) {
if(bills[0] == 10 || bills[0] == 20 || bills[1] == 20){
return false;
}
int count5 = 1;
int count10 = 0;
for(int i = 1; i < bills.length; i++){
if(bills[i] == 5){
count5++;
}
if(bills[i] == 10){
count10++;
if(count5 >= 1){
count5--;
}else{
return false;
}
}
if(bills[i] == 20){
if(count10 >= 1){
if(count5 >= 1){
count10--;
count5--;
}else{
return false;
}
}else{
if(count5 >= 3){
count5 = count5 - 3;
}else{
return false;
}
}
}
}
return true;
}
}