✅ C++ || Easy || Vector Only || STL || Competitive Coding
682. Baseball Game\nKNOCKCAT\n\n\n1. Easy C++\n2. STL functions.\n3. Explanation in comments with code.\n4. If it helps Please Upvote. \u2B06\uFE0F\n5. Link to 
# 682. Baseball Game\n**KNOCKCAT**\n\n```\n1. Easy C++\n2. STL functions.\n3. Explanation in comments with code.\n4. If it helps Please Upvote. \u2B06\uFE0F\n5. Link to my Github Profile contains a repository of Leetcode with all my Solutions. \u2B07\uFE0F\n```\n[LeetCode](https://github.com/knockcat/Leetcode)\n\nPlease upvote my comment so that i get to win the 2022 giveaway and motivate to make such discussion post.\n**Happy new Year 2023 to all of you**\n**keep solving keep improving**\nLink To comment\n[Leetcode Give away comment](https://leetcode.com/discuss/general-discussion/2946993/2022-Annual-Badge-and-the-Giveaway/1734919)\n\n**Functions Used**\n\n```\n1. v.push_back() -> Push(add) an element at the last of a vector.\n2. v.pop_back()  -> Pop(remove) an element from last of vector.\n3. accumulate(v.begin(),v.end(),0) -> sum of all elements(type (int)) in vector.\n// here v.begin() is an iterator or pointer to the first index.\n// v.end() is an iterator or pointer to the last index \n// 0 is passed beacuse at start the sum is 0.\n4. stoi(x) -> convert x which is of string type to int.\n```\n**CODE**\n```\n\t\t\t\t\t\t// \uD83D\uDE09\uD83D\uDE09\uD83D\uDE09\uD83D\uDE09Please upvote if it helps \uD83D\uDE09\uD83D\uDE09\uD83D\uDE09\uD83D\uDE09\nclass Solution {\npublic:\n    int calPoints(vector<string>& ops) {\n        vector<int> v;\n        int j = -1;\n        for(int i = 0; i<ops.size(); ++i)\n        {\n            if(ops[i] == "+")\n            {\n                v.push_back(v[j] + v[j-1]); // if + we have to add the sum of last 2 elements of vector. (v.push_back perform the job for us.)\n                ++j;\n            }\n            else if(ops[i] == "D")\n            {\n                v.push_back(2*v[j]); // if D we have to push twice of the last element (v.push_back() perform the job for us.)\n                ++j;\n            }\n            else if(ops[i] == "C")  // if C we have to delete the last element (v.pop_back() perform the job for us)\n            {\n                v.pop_back(); \n                --j;\n            }\n            else // we have to add the add the element ( v.push_back() perform the job for us)\n            {\n                v.push_back(stoi(ops[i]));  // stoi(converts an string to int) \n                ++j;\n            }\n               \n        }\n\t\treturn accumulate(v.begin(),v.end(),0);   // sum of vector elements.\n    }\n};\n```
['C']