Skip to content

Commit 5258841

Browse files
committed
feat: add ts solution to lc problem: No.0860
1 parent e952593 commit 5258841

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,28 @@ impl Solution {
294294

295295
<!-- solution:end -->
296296

297+
<!-- solution:start -->
298+
299+
### Solution 2: One-liner
300+
301+
<!-- tabs:start -->
302+
303+
#### TypeScript
304+
305+
```ts
306+
const lemonadeChange = (bills: number[], f = 0, t = 0): boolean =>
307+
bills.every(
308+
x => (
309+
(!(x ^ 5) && ++f) ||
310+
(!(x ^ 10) && (--f, ++t)) ||
311+
(!(x ^ 20) && (t ? (f--, t--) : (f -= 3), 1)),
312+
f >= 0
313+
),
314+
);
315+
```
316+
317+
<!-- tabs:end -->
318+
319+
<!-- solution:end -->
320+
297321
<!-- problem:end -->

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,28 @@ impl Solution {
279279

280280
<!-- solution:end -->
281281

282+
<!-- solution:start -->
283+
284+
### Solution 2: One-liner
285+
286+
<!-- tabs:start -->
287+
288+
#### TypeScript
289+
290+
```ts
291+
const lemonadeChange = (bills: number[], f = 0, t = 0): boolean =>
292+
bills.every(
293+
x => (
294+
(!(x ^ 5) && ++f) ||
295+
(!(x ^ 10) && (--f, ++t)) ||
296+
(!(x ^ 20) && (t ? (f--, t--) : (f -= 3), 1)),
297+
f >= 0
298+
),
299+
);
300+
```
301+
302+
<!-- tabs:end -->
303+
304+
<!-- solution:end -->
305+
282306
<!-- problem:end -->
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const lemonadeChange = (bills: number[], f = 0, t = 0): boolean =>
2+
bills.every(
3+
x => (
4+
(!(x ^ 5) && ++f) ||
5+
(!(x ^ 10) && (--f, ++t)) ||
6+
(!(x ^ 20) && (t ? (f--, t--) : (f -= 3), 1)),
7+
f >= 0
8+
),
9+
);

0 commit comments

Comments
 (0)