Python3 || Easy || Beats 100% 🔥🌟 || O(n)
IntuitionThe task involves simulating operations on a scoreboard. The operations are applied sequentially, and the key challenge is correctly interpreting each
### **Intuition**\nThe task involves simulating operations on a scoreboard. The operations are applied sequentially, and the key challenge is correctly interpreting each type of operation and updating the scoreboard accordingly. Using a stack (`answer`) is a natural choice to manage the scores efficiently.\n\n---\n\n### **Approach**\n1. Initialize an empty list (`answer`) to act as the stack for scores.\n2. Iterate over the list of operations (`operations`) and handle each operation:\n   - `"C"`: Remove the last score from the stack using `.pop()`.\n   - `"D"`: Add double the last score (2 \xD7 `answer[-1]`) to the stack.\n   - `"+"`: Add the sum of the last two scores (`answer[-1] + answer[-2]`) to the stack.\n   - Any other value (a number): Convert it to an integer and append it to the stack.\n3. After processing all operations, calculate the total sum of the stack using `sum(answer)`.\n4. Return the computed total.\n\n---\n\n### **Complexity**\n- **Time Complexity:**  \n  Processing each operation is `O(1)`, and there are `n` operations in total. Calculating the sum of the stack at the end is `O(n).`  \n\n\n- **Space Complexity:**  \n  The stack (`answer`) stores scores, which could grow to `O(n)` in size if there are no `"C"` operations.  \n\n\n---\n\n### **Code**\n\n```python\nclass Solution:\n    def calPoints(self, operations: List[str]) -> int:\n        answer = []\n        for i in operations:\n            if i == "C":\n                answer.pop()\n            elif i == "D":\n                answer.append(2 * answer[-1])\n            elif i == "+":\n                answer.append(answer[-1] + answer[-2])\n            else:\n                answer.append(int(i))\n        return sum(answer)\n```\n\n---\n\n\nHappy coding!\n:)\n\n\n
['Array', 'Python3']