LeetCode 682

#682. 棒球比赛
https://leetcode-cn.com/problems/baseball-game/description/
用IDEA和用网站编译答案不一样???(IDEA正确答案)

class Solution {
    public int calPoints(String[] ops) {
        int last = 0;
        int sum = 0;
        int last2 = 0;
        int temp = 0;
        for (int i = 0; i < ops.length; i++) {
            if (ops[i] == "C") {
                sum -= last;
                last = last2;
            }
            else if (ops[i] == "D") {
                last2 = last;
                last = last * 2;
                sum += last;
            }
            else if (ops[i] == "+") {
                temp = last + last2;
                last2 = last;
                last = temp;
                sum += temp;
            }
            else if(ops[i].charAt(0)=='-')
            {
                int c1 = ops[i].charAt(1) -'0';
                last2 = last;
                last = -c1;
                sum -= c1;
            }
            else {
                int ch = ops[i].charAt(0) - '0';
                last2 = last;
                last = ch;
                sum += ch;
            }}
                 return sum;
}}

①不能解决参数是两位数的情况

你可能感兴趣的:(LeetCode 682)