Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions leetcode3/황은지/682. Baseball Game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @param {string[]} operations
* @return {number}
*/
var calPoints = function (operations) {
const stack = [];
for (const op of operations) {
const len = stack.length;
if (op === "D") {
const x = stack[len - 1];
stack.push(+x * 2);
} else if (op === "+") {
const x = stack[len - 1];
const y = stack[len - 2];
stack.push(+x + +y);
} else if (op === "C") stack.pop();
else stack.push(+op);

console.log(stack);
}

let result = 0;
for (const num of stack) {
result += num;
}

return result;
};