Final Value of Variable After Performing Operations

Easy
Watch on YouTube ↗

Solution

class Solution {
    public int finalValueAfterOperations(String[] operations) {
        
        int x = 0;

        for(String op : operations) {
            if(op.indexOf('+')!=-1) {
                x++;
            }
            else x--;
        }

        return x;

    }
}