Skip to content

Commit d7fdf3d

Browse files
committed
feat: update ts solution to lc problem: No.0860
1 parent 9c8672e commit d7fdf3d

File tree

3 files changed

+40
-40
lines changed

3 files changed

+40
-40
lines changed

solution/0800-0899/0860.Lemonade Change/README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -196,31 +196,31 @@ func lemonadeChange(bills []int) bool {
196196

197197
```ts
198198
function lemonadeChange(bills: number[]): boolean {
199-
let five = 0;
200-
let ten = 0;
201-
for (let bill of bills) {
202-
switch (bill) {
203-
case 5:
204-
five++;
205-
break;
206-
case 10:
207-
five--;
208-
ten++;
209-
break;
210-
case 20:
211-
if (ten !== 0) {
212-
ten -= 1;
213-
bill -= 10;
214-
}
215-
five -= bill / 5 - 1;
216-
break;
199+
let [five, ten] = [0, 0]
200+
for (const x of bills) {
201+
switch (x) {
202+
case 5:
203+
five++
204+
break
205+
case 10:
206+
five--
207+
ten++
208+
break
209+
case 20:
210+
if (ten) {
211+
ten--
212+
five--
213+
} else {
214+
five -= 3
217215
}
216+
break
217+
}
218218

219-
if (five < 0) {
220-
return false;
221-
}
219+
if (five < 0) {
220+
return false
222221
}
223-
return true;
222+
}
223+
return true
224224
}
225225
```
226226

solution/0800-0899/0860.Lemonade Change/README_EN.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ tags:
2929
<pre>
3030
<strong>Input:</strong> bills = [5,5,5,10,20]
3131
<strong>Output:</strong> true
32-
<strong>Explanation:</strong>
32+
<strong>Explanation:</strong>
3333
From the first 3 customers, we collect three $5 bills in order.
3434
From the fourth customer, we collect a $10 bill and give back a $5.
3535
From the fifth customer, we give a $10 bill and a $5 bill.
@@ -41,7 +41,7 @@ Since all customers got correct change, we output true.
4141
<pre>
4242
<strong>Input:</strong> bills = [5,5,10,10,20]
4343
<strong>Output:</strong> false
44-
<strong>Explanation:</strong>
44+
<strong>Explanation:</strong>
4545
From the first two customers in order, we collect two $5 bills.
4646
For the next two customers in order, we collect a $10 bill and give back a $5 bill.
4747
For the last customer, we can not give the change of $15 back because we only have two $10 bills.
@@ -181,10 +181,9 @@ func lemonadeChange(bills []int) bool {
181181

182182
```ts
183183
function lemonadeChange(bills: number[]): boolean {
184-
let five = 0;
185-
let ten = 0;
186-
for (let bill of bills) {
187-
switch (bill) {
184+
let [five, ten] = [0, 0];
185+
for (const x of bills) {
186+
switch (x) {
188187
case 5:
189188
five++;
190189
break;
@@ -193,11 +192,12 @@ function lemonadeChange(bills: number[]): boolean {
193192
ten++;
194193
break;
195194
case 20:
196-
if (ten !== 0) {
197-
ten -= 1;
198-
bill -= 10;
195+
if (ten) {
196+
ten--;
197+
five--;
198+
} else {
199+
five -= 3;
199200
}
200-
five -= bill / 5 - 1;
201201
break;
202202
}
203203

solution/0800-0899/0860.Lemonade Change/Solution.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
function lemonadeChange(bills: number[]): boolean {
2-
let five = 0;
3-
let ten = 0;
4-
for (let bill of bills) {
5-
switch (bill) {
2+
let [five, ten] = [0, 0];
3+
for (const x of bills) {
4+
switch (x) {
65
case 5:
76
five++;
87
break;
@@ -11,11 +10,12 @@ function lemonadeChange(bills: number[]): boolean {
1110
ten++;
1211
break;
1312
case 20:
14-
if (ten !== 0) {
15-
ten -= 1;
16-
bill -= 10;
13+
if (ten) {
14+
ten--;
15+
five--;
16+
} else {
17+
five -= 3;
1718
}
18-
five -= bill / 5 - 1;
1919
break;
2020
}
2121

0 commit comments

Comments
 (0)