From 509d70517117c6a2943c269c06beb10a6071be00 Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Wed, 16 Sep 2026 23:43:41 +0900 Subject: [PATCH] 682. Baseball Game --- .../682. Baseball Game.java" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/682. Baseball Game.java" diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/682. Baseball Game.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/682. Baseball Game.java" new file mode 100644 index 00000000..eda78612 --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/682. Baseball Game.java" @@ -0,0 +1,26 @@ +import java.util.*; + +class Solution { + public int calPoints(String[] operations) { + List list = new ArrayList<>(); + + for (String s : operations) { + if (s.equals("+")) { + list.add(list.get(list.size() - 1) + list.get(list.size() - 2)); + } else if (s.equals("D")) { + list.add(list.get(list.size() - 1) * 2); + } else if (s.equals("C")) { + list.remove(list.size() - 1); + } else { + list.add(Integer.parseInt(s)); + } + } + + int ans = 0; + for (int score : list) { + ans += score; + } + + return ans; + } +} \ No newline at end of file