Final Value of Variable After Performing Operations
There is a programming language with only four operations and one variable X: ++X and X++ increment X by 1, while --X and X-- decrement X by 1. X starts at 0. Given an array of strings operations, return the final value of X after performing all the operations.
30:00
Final Value of Variable After Performing Operations
There is a programming language with only four operations and one variable X: ++X and X++ increment X by 1, while --X and X-- decrement X by 1. X starts at 0. Given an array of strings operations, return the final value of X after performing all the operations.
Example 1:
Input: {"operations":["--X","X++","X++"]}
Output: 1
Constraints:
1≤operations.length≤100
operations[i] will be either "++X", "X++", "--X", or "X--".
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"operations":["--X","X++","X++"]}
X starts at 0. There are 3 operations to apply, and only the middle character of each one matters.