Easy Approach and Simple CPP code!💯| Beats 100%
Intuition\nThe calPoints function is designed to evaluate a list of operations related to a baseball scoring system. Each operation in the list modifies the sco
# Intuition\nThe calPoints function is designed to evaluate a list of operations related to a baseball scoring system. Each operation in the list modifies the score in a specific way:\n\nNumber: Add the number to the list of scores.\n"+": Add the sum of the last two scores.\n"D": Double the last score.\n"C": Remove the last score.\n\n# Approach\n1.Initialization:\n\nCreate a vector a to keep track of the scores.\n\n2.Processing Operations:\n\nIterate through each operation in the operations vector.\nFor each operation, perform the following based on its type:\nNumber: Convert the string to an integer using stoi and push it to the vector a.\n"+": Compute the sum of the last two scores and add this sum to the vector a.\n"D": Double the last score and push this value to the vector a.\n"C": Remove the last score from the vector a.\n\n3.Compute Total Score:\n\nAfter processing all operations, calculate the total score by summing all elements in the vector a using std::accumulate.\n\n# Complexity\n- Time complexity:O(n)\n\n- Space complexity:O(n)\n\n# Code\n```\nclass Solution {\npublic:\n    int calPoints(vector<string>& operations) {\n        vector<int> a;\n        \n        for (const string& op : operations) {\n            if (op == "+") {\n                a.push_back(a[a.size() - 1] + a[a.size() - 2]);\n            } \n            else if (op == "D") \n            {\n                a.push_back(2 * a.back());\n            } \n            else if (op == "C") {\n                a.pop_back();\n            } \n            else {\n                a.push_back(stoi(op));\n            }\n        } \n        return accumulate(a.begin(), a.end(), 0);\n    }\n};\n```
['C++']