Java Solution | Stacks ✨
\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
\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        for(int i=0; i<operations.length; i++){\n            if(operations[i].equals("C")){\n                stack.pop();\n            }\n            else if(operations[i].equals("D")){\n                stack.push(2* stack.peek());\n            }\n            else if(operations[i].equals("+") && stack.size()>=2){\n                int x = stack.pop();\n                int y = stack.pop();\n                int z = x+y;\n\n                stack.push(y);\n                stack.push(x);\n                stack.push(z);\n            }\n            else{\n                stack.push(Integer.parseInt(operations[i]));\n            }\n        }\n        int sum =0;\n        while(!stack.isEmpty()){\n            sum+=stack.pop();\n        }\n        return sum;\n    }\n}\n```
['Stack', 'Java']