image_2021-10-20_03-07-25.png
36.8 KB
#N2011. Final Value of Variable After Performing Operations
problem link=>https://leetcode.com/problems/final-value-of-variable-after-performing-operations/
#solution
problem link=>https://leetcode.com/problems/final-value-of-variable-after-performing-operations/
#solution
class Solution {
public int finalValueAfterOperations(String[] operations) {
int x=0;
for(int i=0; i<operations.length; i++){
if(operations[i].contains("++")){
x++;
}
if(operations[i].contains("--")){
x--;
}
}
return x;
}
}