Baseball Game | C++, Correct the solution.
help me finding bug in this solution\n\nclass Solution {\npublic:\n    int calPoints(vector& ops) {\n        vectorscores;\n        int idx = 0;\n        for (s
help me finding bug in this solution\n\nclass Solution {\npublic:\n    int calPoints(vector<string>& ops) {\n        vector<int>scores;\n        int idx = 0;\n        for (string op : ops){\n            if (op=="+") {\n                scores[idx] = scores[idx - 1] + scores[idx - 2];\n                idx++;\n            } else if (op=="D") {\n                scores[idx] = 2 * scores[idx - 1];\n                idx++;\n            } else if (op=="C") {\n                idx--;\n                scores[idx] = 0;\n            } else {\n                scores.push_back(stoi(op));\n                idx++;\n            }\n        }\n        \n        int ans = 0;\n        for (int score : scores) {\n            ans += score;\n        }\n        return ans;\n    }\n};
[]