Clean C++ Solution


  • 0
    Z
        int calPoints(vector<string>& ops) {
            vector<int> my_vec;
            for(int i = 0; i < ops.size(); ++i) {
                if("C" == ops[i]) {
                    my_vec.pop_back();
                } else {
                    my_vec.push_back(i);
                }
            }
            int sum = 0;
            for(int i = 0; i < my_vec.size(); ++i) {
                my_vec[i] = ("D" == ops[my_vec[i]]) ? my_vec[i - 1] << 1 : 
                        ("+" == ops[my_vec[i]]) ? my_vec[i - 1] + my_vec[i - 2] : stoi(ops[my_vec[i]]);
                sum += my_vec[i];
            }
            return sum;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.