LeetCode_682-Baseball Game

Given a list of strings, a string contains an integer, '+', 'D', 'C', representing a fraction of an integer of, the '+' represents a significant fraction of the two and, after the 'D' represents a significant fraction of twice, the 'C' on behalf of deleting a valid point values, and finally find all valid and scores.
Examples:
input [ "5", "2" , "C", "D", "+"], the number of invalid output 30.2, 'D' is 5 * 2, '+' is 5 * 2 + 5,5 + 0 + 10 + (10 + 5) = 30

class Solution {
public:
    int calPoints(vector<string>& ops) {
        stack<int> stackRes;
        for(int i=0; i<ops.size(); i++) {
            if(ops[i][0] == 'C') {
                if(!stackRes.empty()) {
                    stackRes.pop();
                }
            }
            else if(ops[i][0] == 'D' ) {
                 If (! StackRes.empty ()) {
                     int nnum = stackRes.top (); 
                    nnum * = 2 ; 
                    stackRes.push (nnum); 
                } 
            } 
            Else  if (ops [i] [ 0 ] == ' + ' ) {
                 if (! StackRes.empty ()) {
                     int nnum = stackRes.top (); 
                    stackRes.pop (); 
                    int -ēnsumus nnum = +  stackRes.top ();
                    stackRes.push (nnum);
                    stackRes.push(nSum);
                }
            }
            else {
                stackRes.push(atoi(ops[i].c_str()));
            }
        }
        int nResRum = 0;
        while(!stackRes.empty()) {
            nResRum += stackRes.top();
            stackRes.pop();
        }
        return nResRum;
    }
};

Number may be concerned about the public learn more about interview skills

Guess you like

Origin www.cnblogs.com/yew0/p/11613927.html