682. Baseball Game

Posted jtechroad

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了682. Baseball Game相关的知识,希望对你有一定的参考价值。

class Solution {
public:
    int calPoints(vector<string>& ops) {
        vector<int> v;
        for (auto &s : ops) {
            if (s == "+") {
                v.push_back(v[v.size()-1] + v[v.size()-2]);
            }
            else if (s == "D") {
                v.push_back(v.back() * 2);
            }
            else if (s == "C") {
                v.pop_back();
            }
            else
                v.push_back(stoi(s));
        }
        int res = 0;
        for (auto i : v)
            res += i;
        return res;
    }
};

 

以上是关于682. Baseball Game的主要内容,如果未能解决你的问题,请参考以下文章

682. Baseball Game

[leetcode-682-Baseball Game]

leetcode-682-Baseball Game

682. Baseball Game

682. Baseball Game

[LeetCode&Python] Problem 682. Baseball Game