Practice Final Value of Variable After Performing Operations
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Begin with X = 0. For each string in operations, add 1 for ++X or X++, and subtract 1 for --X or X--. Return X after all operations.
Source: Final Value of Variable After Performing Operations on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
operations = ["--X","X++","X++"]
Output
1
# Example 2
Input
operations = ["++X","++X","X++"]
Output
3
# Example 3
Input
operations = ["X++","++X","--X","X--"]
Output
0
Constraints
1 <= operations.length <= 100
operations[i] will be either "++X", "X++", "--X", or "X--".
Related LeetCode Problems
Practice more problems similar to Final Value of Variable After Performing Operations.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.