One traversal | | stack C++
\n# Code\n\nclass Solution {\npublic:\n    int calPoints(vector<string>& operations) {\n        stack<int>st;\n        int sum=0;\n        for(int i=0;i<operati
\n# Code\n```\nclass Solution {\npublic:\n    int calPoints(vector<string>& operations) {\n        stack<int>st;\n        int sum=0;\n        for(int i=0;i<operations.size();i++){\n            if(operations[i]=="D"){\n                int x=st.top()*2;\n                st.push(x);\n                sum=sum+st.top();\n            }\n            else if(operations[i]=="C"){\n             sum=sum-st.top();\n             st.pop();\n            }\n            else if(operations[i]=="+"){\n                int temp=st.top();\n                st.pop();\n                int y=st.top()+temp;\n                st.push(temp);\n                st.push(y);\n                sum=sum+st.top();\n\n            }\n            else{\n                st.push(stoi(operations[i]));\n                sum=sum+st.top();\n            }\n        }\n     return sum;\n    }\n};\n```
['Stack', 'C++']