682. 棒球比赛
2019-02-18 本文已影响0人
上杉丶零
class Solution {
public int calPoints(String[] ops) {
List<Integer> iList = new ArrayList<Integer>();
for (String s : ops) {
switch (s.charAt(0)) {
case '+':
iList.add(iList.get(iList.size() - 1) + iList.get(iList.size() - 2));
break;
case 'D':
iList.add(iList.get(iList.size() - 1) * 2);
break;
case 'C':
iList.remove(iList.size() - 1);
break;
default:
iList.add(Integer.parseInt(s));
break;
}
}
int sum = 0;
for (int i : iList) {
sum += i;
}
return sum;
}
}
