|
| 1 | +<h2><a href="https://leetcode.com/problems/lemonade-change/">860. Lemonade Change</a></h2><h3>Easy</h3><hr><p>At a lemonade stand, each lemonade costs <code>5ドル</code>. 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 <code>5ドル</code>, <code>10ドル</code>, or <code>20ドル</code> bill. You must provide the correct change to each customer so that the net transaction is that the customer pays <code>5ドル</code>.</p> |
| 2 | + |
| 3 | +<p>Note that you do not have any change in hand at first.</p> |
| 4 | + |
| 5 | +<p>Given an integer array <code>bills</code> where <code>bills[i]</code> is the bill the <code>i<sup>th</sup></code> customer pays, return <code>true</code> <em>if you can provide every customer with the correct change, or</em> <code>false</code> <em>otherwise</em>.</p> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | + |
| 10 | +<pre> |
| 11 | +<strong>Input:</strong> bills = [5,5,5,10,20] |
| 12 | +<strong>Output:</strong> true |
| 13 | +<strong>Explanation:</strong> |
| 14 | +From the first 3 customers, we collect three 5ドル bills in order. |
| 15 | +From the fourth customer, we collect a 10ドル bill and give back a 5ドル. |
| 16 | +From the fifth customer, we give a 10ドル bill and a 5ドル bill. |
| 17 | +Since all customers got correct change, we output true. |
| 18 | +</pre> |
| 19 | + |
| 20 | +<p><strong class="example">Example 2:</strong></p> |
| 21 | + |
| 22 | +<pre> |
| 23 | +<strong>Input:</strong> bills = [5,5,10,10,20] |
| 24 | +<strong>Output:</strong> false |
| 25 | +<strong>Explanation:</strong> |
| 26 | +From the first two customers in order, we collect two 5ドル bills. |
| 27 | +For the next two customers in order, we collect a 10ドル bill and give back a 5ドル bill. |
| 28 | +For the last customer, we can not give the change of 15ドル back because we only have two 10ドル bills. |
| 29 | +Since not every customer received the correct change, the answer is false. |
| 30 | +</pre> |
| 31 | + |
| 32 | +<p> </p> |
| 33 | +<p><strong>Constraints:</strong></p> |
| 34 | + |
| 35 | +<ul> |
| 36 | + <li><code>1 <= bills.length <= 10<sup>5</sup></code></li> |
| 37 | + <li><code>bills[i]</code> is either <code>5</code>, <code>10</code>, or <code>20</code>.</li> |
| 38 | +</ul> |
0 commit comments