We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents d803f93 + 8db5099 commit 104e483Copy full SHA for 104e483
javascript/682-Baseball-Game.js
@@ -0,0 +1,29 @@
1
+/**
2
+ * @param {string[]} operations
3
+ * @return {number}
4
+ */
5
+var calPoints = function(operations) {
6
+ let runningSum = 0;
7
+ const stack = [];
8
+ for(const o of operations) {
9
+ if(o === 'C') {
10
+ runningSum -= stack.pop();
11
+ continue;
12
+ }
13
+ if(o === 'D') {
14
+ const val = stack[stack.length - 1] * 2;
15
+ stack.push(val);
16
+ runningSum += val;
17
18
19
+ if(o === '+') {
20
+ const val = stack[stack.length - 1] + stack[stack.length - 2];
21
22
23
24
25
+ stack.push(+o);
26
+ runningSum += +o;
27
28
+ return runningSum;
29
+};
0 commit comments