Using vector as stack & accumulate||0ms beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nThis question needs a container, since \n> Return the sum of all the scores on the reco
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis question needs a container, since \n> Return the sum of all the scores on the record after applying all the operations.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Use C++ std::vector as a stack to store the numbers.\n2. Use a loop to transverse\n3. There are 4 different cases to apply the different operations; it would be suited to use switch-case\n4. Return the sum of numbers in stack by using std::accumulate\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n $$O(n)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n $$O(n)$$\n# Code||C++ 0ms beats 100%\n```\nclass Solution {\npublic:\n    static int calPoints(vector<string>& operations) {\n        vector<int> stack;\n        for(string& s: operations){\n            char c=s[0];\n            switch(c){\n                case \'+\': stack.push_back(stack.back()+(*(stack.end()-2))); break;\n                case \'D\': stack.push_back(stack.back()*2); break;\n                case \'C\': stack.pop_back(); break;\n                default: stack.push_back(stoi(s));\n            }\n        }\n        return accumulate(stack.begin(), stack.end(), 0);\n    }\n};\n\n\n\n\nauto init = []() {\n    ios::sync_with_stdio(false);\n    cin.tie(nullptr);\n    cout.tie(nullptr);\n    return \'c\';\n}();\n```
['Array', 'Stack', 'Simulation', 'C++']