|
| 1 | +<h2>unknown-problem</h2><h3>Easy</h3><hr><div><p>At a lemonade stand, each lemonade costs <code>$5</code>. </p> |
| 2 | + |
| 3 | +<p>Customers are standing in a queue to buy from you, and order one at a time (in the order specified by <code>bills</code>).</p> |
| 4 | + |
| 5 | +<p>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 $5.</p> |
| 6 | + |
| 7 | +<p>Note that you don't have any change in hand at first.</p> |
| 8 | + |
| 9 | +<p>Return <code>true</code> if and only if you can provide every customer with correct change.</p> |
| 10 | + |
| 11 | +<p> </p> |
| 12 | + |
| 13 | +<div> |
| 14 | +<p><strong>Example 1:</strong></p> |
| 15 | + |
| 16 | +<pre><strong>Input: </strong><span id="example-input-1-1">[5,5,5,10,20]</span> |
| 17 | +<strong>Output: </strong><span id="example-output-1">true</span> |
| 18 | +<strong>Explanation: </strong> |
| 19 | +From the first 3 customers, we collect three $5 bills in order. |
| 20 | +From the fourth customer, we collect a $10 bill and give back a $5. |
| 21 | +From the fifth customer, we give a $10 bill and a $5 bill. |
| 22 | +Since all customers got correct change, we output true. |
| 23 | +</pre> |
| 24 | + |
| 25 | +<div> |
| 26 | +<p><strong>Example 2:</strong></p> |
| 27 | + |
| 28 | +<pre><strong>Input: </strong><span id="example-input-2-1">[5,5,10]</span> |
| 29 | +<strong>Output: </strong><span id="example-output-2">true</span> |
| 30 | +</pre> |
| 31 | + |
| 32 | +<div> |
| 33 | +<p><strong>Example 3:</strong></p> |
| 34 | + |
| 35 | +<pre><strong>Input: </strong><span id="example-input-3-1">[10,10]</span> |
| 36 | +<strong>Output: </strong><span id="example-output-3">false</span> |
| 37 | +</pre> |
| 38 | + |
| 39 | +<div> |
| 40 | +<p><strong>Example 4:</strong></p> |
| 41 | + |
| 42 | +<pre><strong>Input: </strong><span id="example-input-4-1">[5,5,10,10,20]</span> |
| 43 | +<strong>Output: </strong><span id="example-output-4">false</span> |
| 44 | +<strong>Explanation: </strong> |
| 45 | +From the first two customers in order, we collect two $5 bills. |
| 46 | +For the next two customers in order, we collect a $10 bill and give back a $5 bill. |
| 47 | +For the last customer, we can't give change of $15 back because we only have two $10 bills. |
| 48 | +Since not every customer received correct change, the answer is false. |
| 49 | +</pre> |
| 50 | + |
| 51 | +<p> </p> |
| 52 | + |
| 53 | +<p><strong><span>Note:</span></strong></p> |
| 54 | + |
| 55 | +<ul> |
| 56 | + <li><code>0 <= bills.length <= 10000</code></li> |
| 57 | + <li><code>bills[i]</code> will be either <code>5</code>, <code>10</code>, or <code>20</code>.</li> |
| 58 | +</ul> |
| 59 | +</div> |
| 60 | +</div> |
| 61 | +</div> |
| 62 | +</div> |
| 63 | +</div> |
0 commit comments