682. 棒球比赛
作者:
上杉丶零 | 来源:发表于
2019-02-18 21:35 被阅读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;
}
}
image.png
本文标题:682. 棒球比赛
本文链接:https://www.haomeiwen.com/subject/luazeqtx.html
网友评论