Simple java solution using stack
since we want to look always last element (atmost last 2) everytime. hence stack is best suitable for it.\n\npublic int calPoints(String[] ops) {\n        Deque
since we want to look always last element (atmost last 2) everytime. hence stack is best suitable for it.\n```\npublic int calPoints(String[] ops) {\n        Deque<Integer> stack = new LinkedList<>();\n        for(String val:ops) {\n            if("+".equals(val)) {\n                int op1 = stack.pop();\n                int op2 = op1 + stack.peek();\n                stack.push(op1);\n                stack.push(op2);\n            } else if("C".equals(val)) {\n                stack.pop();\n            } else if("D".equals(val)) {\n                stack.push(2*stack.peek());\n            } else {\n                stack.push(Integer.parseInt(val));\n            }\n        }\n        int res=0;\n        while(!stack.isEmpty()) {\n            res+=stack.pop();\n        }\n        return res;\n    }\n```
['Java']