总结,玩爽了,回归。
java
class Solution {
public int finalValueAfterOperations(String[] operations) {
int x = 0;
for(String op : operations) {
if (op.equals("X++") || op.equals("++X")){
x ++ ;
}
else x -- ;
}
return x;
}
}
cpp
class Solution {
public:
int finalValueAfterOperations(vector<string>& operations) {
int x = 0;
for (auto &op : operations) {
op[1] == '+' ? x ++ : x -- ;
}
return x;
}
};