• 0 <= bills.length <= 10000
• bills[i] 不是 5 就是 10 或是 20

Customers are standing in a queue to buy from you, and order one at a time (in the order specified by bills).

Each customer will only buy one lemonade and pay with either a \$5, \$10, or \$20 bill.  You must provide the correct change to each customer, so that the net transaction is that the customer pays \$5.

Note that you don’t have any change in hand at first.

Return true if and only if you can provide every customer with correct change.

Input: [5,5,5,10,20]

Output: true

Explanation: From the first 3 customers, we collect three \$5 bills in order.From the fourth customer, we collect a \$10 bill and give back a \$5.From the fifth customer, we give a \$10 bill and a \$5 bill.Since all customers got correct change, we output true.

Input: [5,5,10]

Output: true

Input: [10,10]

Output: false

Input: [5,5,10,10,20]

Output: false

Explanation: From the first two customers in order, we collect two \$5 bills.For the next two customers in order, we collect a \$10 bill and give back a \$5 bill.For the last customer, we can’t give change of \$15 back because we only have two \$10 bills.Since not every customer received correct change, the answer is false.

Note:

• 0 <= bills.length <= 10000
• bills[i] will be either 5, 10, or 20.

```public class Program {

public static void Main(string[] args) {
var bills = new int[] { 5, 5, 5, 10, 20 };

Console.WriteLine(res);

bills = new int[] { 5, 5, 10, 10, 20 };

Console.WriteLine(res);

bills = new int[] { 5, 10 };

Console.WriteLine(res);

}

public static bool LemonadeChange(int[] bills) {
//统计5美元和10美元的数量
var five = 0;
var ten = 0;
for(var i = 0; i < bills.Length; i++) {
if(bills[i] == 5) {
//5美元，则5美元+1
five++;
} else if(bills[i] == 10) {
//10美元，则10美元+1，找零5美元，5美元-1
ten++;
five--;
} else if(bills[i] == 20) {
//20美元时，尽量先找零10美元和5美元
//然后考虑找零3个5美元
if(ten > 0) {
ten--;
five--;
} else {
five -= 3;
}
}
//5美元或10美元小于0时，说明至少有1次找零是失败的
//直接返回 false
if(five < 0 || ten < 0) return false;
}
//最后返回 true
return true;
}

public static bool LemonadeChange2(int[] bills) {
var list = new List<int>();
for(var i = 0; i < bills.Length; i++) {
if(bills[i] == 5) {
} else if(bills[i] == 10) {
if(!list.Remove(5)) return false;
} else if(bills[i] == 20) {
if(list.Remove(10)) {
if(!list.Remove(5)) return false;
} else {
for(var j = 0; j < 3; j++) {
if(!list.Remove(5)) return false;
}
}
}
}
return true;
}

public static bool LemonadeChange3(int[] bills) {
//不建议的解法，仅提供思路
try {
var five = new Stack<int>();
var ten = new Stack<int>();
for(var i = 0; i < bills.Length; i++) {
if(bills[i] == 5) {
five.Push(5);//这个值是什么无所谓
} else if(bills[i] == 10) {
ten.Push(10);//这个值是什么无所谓
five.Pop();
} else if(bills[i] == 20) {
if(ten.Any()) {
ten.Pop();
five.Pop();
} else {
for(var j = 0; j < 3; j++) {
five.Pop();
}
}
}
}
return true;
} catch(Exception ex) {
return false;
}
}

}```

```True
False
True```