Simple java solution
Approach\n\n\nThis Java code defines a class called Solution with a method calPoints that calculates the sum of valid points based on a list of operations. The 
Approach\n\n\nThis Java code defines a class called Solution with a method calPoints that calculates the sum of valid points based on a list of operations. The operations are represented as an array of strings op. The operations can be of four types:\n\n* Integer: Represents a valid point, and it is pushed onto the stack.\n* "C": Represents an invalid operation and removes the last valid point from the stack.\n* "D": Represents a double operation, where the last valid point is doubled and pushed onto the stack.\n* "+": Represents an addition operation, where the last two valid points are summed, and the result is pushed onto the stack.\n\nLet\'s go through the code step by step:\n\n1.The method calPoints takes the op array as input and initializes an empty stack st to hold the valid points.\n\n2.The code then iterates through each element of the op array using a for-loop.\n3. For each element, it checks the type of operation:\n\n * If the operation is "C" (char at index 0), and the stack is not empty, it means we need to remove the last valid point. Thus, the last element is popped from the stack using st.pop().\n * If the operation is "D", it means we need to double the last valid point and push it onto the stack. This is done by popping the last element from the stack (st.peek()) and pushing its doubled value (2 * st.peek()).\n * If the operation is "+", it means we need to add the last two valid points and push the result onto the stack. To achieve this, the last two elements are popped from the stack, their sum is calculated, and the three elements (last two popped and the sum) are pushed back onto the stack in the same order.\n * If the operation is none of the above ("C", "D", or "+"), it means the operation represents a valid point (integer). In this case, the integer value is parsed from the string (Integer.parseInt(op[i])) and pushed onto the stack.\n \n 4.After processing all the operations, the code proceeds to calculate the final sum of all valid points stored in the stack. It pops elements from the stack one by one and adds them to the ans variable.\n\n5.Finally, the method returns the sum (ans) as the result.\n\nThis code efficiently processes the list of operations and calculates the sum of valid points using a stack, which is a suitable data structure for this problem since it involves the concept of "last valid point" and its potential removal or duplication.\n\nComplexity\n\nTime Complexity:\n\nThe code iterates through each element in the op array once using a for-loop. The loop runs op.length times.\nFor each operation, the time complexity of processing it is constant, as the operations on the stack (push, pop, peek) are all O(1) operations.\nTherefore, the overall time complexity of the code is O(N), where N is the length of the op array.\n\nSpace Complexity:\n\nThe space complexity is determined by the space used by the stack st, which holds the valid points during the processing of the operations.\nIn the worst case, the stack could store all the valid points present in the op array (when there are no "C" operations). In this case, the space complexity would be O(N).\nHowever, note that the stack would not store more than N elements at any point in time since each "C" operation removes one valid point. Therefore, the space complexity in the average case would be less than O(N).\nThus, the space complexity of the code is O(N) on average and in the worst case.\n\n```\nclass Solution {\n    public int calPoints(String[] op) {\n        Stack<Integer> st = new Stack<>();\n        for(int i = 0;i<op.length;i++){\n            if(op[i].charAt(0) == \'C\' && st.empty()!=true){st.pop();}\n            else if(op[i].charAt(0) == \'D\' ){st.push(2*st.peek());}\n            else if(op[i].charAt(0) ==\'+\'){\n                int v2 = st.pop();\n                int v1 = st.pop();\n                int v3 = v1+v2;\n                st.push(v1);\n                st.push(v2);\n                st.push(v3);\n            }\n            else if(op[i].charAt(0) != \'C\'){\n                st.push(Integer.parseInt(op[i]));\n            }\n        }\n        int ans = 0;\n        while(st.empty()!=true){\n            ans = ans + st.pop();\n        }\n        return ans;\n    }\n}\n```
['Java']