题目来源:
leetcode题目,网址:2011. 执行操作后的变量值 - 力扣(LeetCode)
解题思路:
按要求遍历字符串数组并根据字符串内容进行相应操作即可。
解题代码:
class Solution {
public int finalValueAfterOperations(String[] operations) {
int res=0;
for(String operation:operations){
if(operation.indexOf('+')!=-1){
res++;
}else{
res--;
}
}
return res;
}
}
总结:
官方题解也是一样的解法,模拟。