JAVA Easy Solution 🔥100% Faster Code 🔥Beginner Friendly🔥
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int calPoints(String[] operations) {\n        Stack<Integer> stack = new Stack<>();\n        int result = 0;\n        for (String operation : operations) {\n            switch (operation) {\n                case "+" -> {\n                    int res = stack.get(stack.size() - 2) + stack.peek();\n                    stack.add(res);\n                    result += res;\n                }\n                case "D" -> {\n                    int res = stack.peek() * 2;\n                    stack.add(res);\n                    result += res;\n                }\n                case "C" -> result -= stack.pop();\n                default -> {\n                    int res = Integer.parseInt(operation);\n                    stack.add(res);\n                    result+=res;\n                }\n            }\n        }\n        return result;\n    }\n}\n```
['Java']