File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 186
186
| 704| [ 二分查找] ( https://leetcode.cn/problems/binary-search/ ) | [ JavaScript] ( ./algorithms/binary-search.js ) | Easy|
187
187
| 707| [ 设计链表] ( https://leetcode.cn/problems/design-linked-list/ ) | [ JavaScript] ( ./algorithms/design-linked-list.js ) | Medium|
188
188
| 844| [ 比较含退格的字符串] ( https://leetcode.cn/problems/backspace-string-compare/ ) | [ JavaScript] ( ./algorithms/backspace-string-compare.js ) | Easy|
189
+ | 860| [ 柠檬水找零] ( https://leetcode.cn/problems/lemonade-change/ ) | [ JavaScript] ( ./algorithms/lemonade-change.js ) | Easy|
189
190
| 876| [ 链表的中间结点] ( https://leetcode.cn/problems/middle-of-the-linked-list/ ) | [ JavaScript] ( ./algorithms/middle-of-the-linked-list.js ) | Easy|
190
191
| 897| [ 递增顺序搜索树] ( https://leetcode.cn/problems/increasing-order-search-tree/ ) | [ JavaScript] ( ./algorithms/increasing-order-search-tree.js ) | Easy|
191
192
| 904| [ 水果成篮] ( https://leetcode.cn/problems/fruit-into-baskets/ ) | [ JavaScript] ( ./algorithms/fruit-into-baskets.js ) | Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 860. 柠檬水找零
3
+ * @param {number[] } bills
4
+ * @return {boolean }
5
+ */
6
+ var lemonadeChange = function ( bills ) {
7
+ // 面额: 5 10 20
8
+
9
+ let five = 0 ;
10
+ let ten = 0 ;
11
+
12
+ for ( let i = 0 ; i < bills . length ; i ++ ) {
13
+ const curr = bills [ i ] ;
14
+ if ( curr === 5 ) {
15
+ five ++ ;
16
+ } else if ( curr === 10 ) {
17
+ ten ++ ;
18
+ five -- ; // 找零 5
19
+ } else if ( ten > 0 ) {
20
+ // curr: 20, 找零 5, 10
21
+ ten -- ;
22
+ five -- ;
23
+ } else {
24
+ // curr: 20, 找零 5 * 3
25
+ five -= 3 ;
26
+ }
27
+ if ( five < 0 ) {
28
+ return false ;
29
+ }
30
+ }
31
+
32
+ return true ;
33
+ } ;
You can’t perform that action at this time.
0 commit comments