Final Value of Variable After Operations

Easy

Starting from X = 0, apply every operation in operations and return the final value of X.

++X and X++ both add 1; --X and X-- both subtract 1.

Example 1

finalValue()
Input
operations = ["--X","X++","X++"]
Output
1

Example 2

finalValue()
Input
operations = ["++X","++X","X++"]
Output
3
Constraints
1 <= operations.length <= 100
Every operation is one of `++X`, `X++`, `--X`, `X--`.

Topics

StringsSimulation

Implement finalValue in the editor and return the answer — printing it is never graded.