2011. 执行操作后的变量值
[2011. 执行操作后的变量值] (https://leetcode.cn/problems/final-value-of-variable-after-performing-operations/description/)
class Solution {
public int finalValueAfterOperations(String[] operations) {
int res = 0;
for (String operation : operations) {
switch (operation) {
case "--X" :
case "X--" :
res --; break;
case "X++" :
case "++X" :
res ++; break;
default: break;
}
}
return res;
}
}