860. Lemonade Change Easy

@problem@discussion
#Array#Greedy



1/**
2 * [860] Lemonade Change
3 *
4 * At a lemonade stand, each lemonade costs $5. 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.
5 * Note that you do not have any change in hand at first.
6 * Given an integer array bills where bills[i] is the bill the i^th customer pays, return true if you can provide every customer with the correct change, or false otherwise.
7 *  
8 * Example 1:
9 * 
10 * Input: bills = [5,5,5,10,20]
11 * Output: true
12 * Explanation: 
13 * From the first 3 customers, we collect three $5 bills in order.
14 * From the fourth customer, we collect a $10 bill and give back a $5.
15 * From the fifth customer, we give a $10 bill and a $5 bill.
16 * Since all customers got correct change, we output true.
17 * 
18 * Example 2:
19 * 
20 * Input: bills = [5,5,10,10,20]
21 * Output: false
22 * Explanation: 
23 * From the first two customers in order, we collect two $5 bills.
24 * For the next two customers in order, we collect a $10 bill and give back a $5 bill.
25 * For the last customer, we can not give the change of $15 back because we only have two $10 bills.
26 * Since not every customer received the correct change, the answer is false.
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	1 <= bills.length <= 10^5
32 * 	bills[i] is either 5, 10, or 20.
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/lemonade-change/
38// discuss: https://leetcode.com/problems/lemonade-change/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn lemonade_change(bills: Vec<i32>) -> bool {
44        false
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_860() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.