package leetcode;

/**
 * https://leetcode.com/problems/baseball-game/
 */
public class Problem682 {
    public int calPoints(String[] ops) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem682 prob = new Problem682();
        System.out.println(prob.calPoints(new String[]{"5", "2", "C", "D", "+"})); // 15
        System.out.println(prob.calPoints(new String[]{"5", "-2", "4", "C", "D", "9", "+", "+"})); // 27
    }
}

@@ -12,16 +12,68 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 /**%0A * h
@@ -199,15 +199,810 @@
     
-// TODO
+int sum = 0;%0A        List%3CInteger%3E list = new ArrayList%3C%3E();%0A        int index = 0;%0A        for (int i = 0; i %3C ops.length; i++) %7B%0A            String op = ops%5Bi%5D;%0A            if (op.equals(%22D%22)) %7B%0A                int a = list.get(list.size() - 1) * 2;%0A                sum += a;%0A                list.add(sum);%0A            %7D else if (op.equals(%22C%22)) %7B%0A                sum -= Integer.parseInt(ops%5Bindex%5D);%0A                list.remove(list.size() - 1);%0A            %7D else if (op.equals(%22+%22)) %7B%0A                int a = list.get(list.size() - 1);%0A                int b = list.get(list.size() - 2);%0A                sum += (a + b);%0A                list.add(sum);%0A            %7D else %7B%0A                index = i;%0A                sum += Integer.parseInt(op);%0A                list.add(sum);%0A            %7D%0A        %7D
 %0A   
@@ -1013,17 +1013,19 @@
  return 
-0
+sum
 ;%0A    %7D%0A

Update problem 682