From 5b5dc946c451d00c02ede15234400750814d4497 Mon Sep 17 00:00:00 2001 From: dmswl6310 Date: Wed, 16 Sep 2026 10:27:33 +0900 Subject: [PATCH] 0916 --- .../682. Baseball Game.js" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "leetcode3/\355\231\251\354\235\200\354\247\200/682. Baseball Game.js" diff --git "a/leetcode3/\355\231\251\354\235\200\354\247\200/682. Baseball Game.js" "b/leetcode3/\355\231\251\354\235\200\354\247\200/682. Baseball Game.js" new file mode 100644 index 00000000..7f3fcf15 --- /dev/null +++ "b/leetcode3/\355\231\251\354\235\200\354\247\200/682. Baseball Game.js" @@ -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; +};