File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 118
118
| 637| [ 二叉树的层平均值] ( https://leetcode.cn/problems/average-of-levels-in-binary-tree/ ) | [ JavaScript] ( ./algorithms/average-of-levels-in-binary-tree.js ) | Easy|
119
119
| 645| [ 错误的集合] ( https://leetcode.cn/problems/set-mismatch/ ) | [ JavaScript] ( ./algorithms/set-mismatch.js ) | Easy|
120
120
| 657| [ 机器人能否返回原点] ( https://leetcode.cn/problems/robot-return-to-origin/ ) | [ JavaScript] ( ./algorithms/robot-return-to-origin.js ) | Easy|
121
+ | 682| [ 棒球比赛] ( https://leetcode.cn/problems/baseball-game/ ) | [ JavaScript] ( ./algorithms/baseball-game.js ) | Easy|
121
122
| 687| [ 最长同值路径] ( https://leetcode.cn/problems/longest-univalue-path/ ) | [ JavaScript] ( ./algorithms/longest-univalue-path.js ) | Medium|
122
123
| 700| [ 二叉搜索树中的搜索] ( https://leetcode.cn/problems/search-in-a-binary-search-tree/ ) | [ JavaScript] ( ./algorithms/search-in-a-binary-search-tree.js ) | Easy|
123
124
| 704| [ 二分查找] ( https://leetcode.cn/problems/binary-search/ ) | [ JavaScript] ( ./algorithms/binary-search.js ) | Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string[] } ops
3
+ * @return {number }
4
+ */
5
+ var calPoints = function ( ops ) {
6
+ const stack = [ ] ;
7
+
8
+ for ( let s of ops ) {
9
+ if ( + s === + s ) {
10
+ stack . push ( s ) ;
11
+ } else if ( s === "C" ) {
12
+ stack . pop ( ) ;
13
+ } else if ( s === "D" ) {
14
+ stack . push ( stack . at ( - 1 ) * 2 ) ;
15
+ } else if ( s === "+" ) {
16
+ stack . push ( Number ( stack . at ( - 1 ) ) + Number ( stack . at ( - 2 ) ) ) ;
17
+ }
18
+ }
19
+
20
+ return stack . reduce ( ( a , b ) => Number ( a ) + Number ( b ) , 0 ) ;
21
+ } ;
You can’t perform that action at this time.
0 commit comments