Description
There is a programming language with only four operations: ++X, X++, --X, X--. Initially X=0. Given an array of operations, return the final value of X.
Examples
Input:
operations = ["--X","X++","X++"]Output:
1Explanation:
-1 +1 +1 = 1.
Input:
operations = ["X++","++X","--X","X--"]Output:
0Explanation:
Two increments (+1, +1) and two decrements (-1, -1) cancel out: 0 + 1 + 1 - 1 - 1 = 0.
Input:
operations = ["++X","--X","++X","X--","X++"]Output:
1Explanation:
Starting at 0: ++X gives 1, --X gives 0, ++X gives 1, X-- gives 0, X++ gives 1. Final result: 1.
Constraints
- •
1 ≤ operations.length ≤ 100