Tap here to switch tabs
Problem
Submissions

Problem: Final Value of Variable After Performing Operations

med
30 min
Try to solve the Final Value of Variable After Performing Operations problem.

Statement

There is a single variable X that initially has a value of 00.

You are given an array of strings operations containing operations that modify the value of X:

  • "++X" and "X++" increment the value of X by 11.

  • "--X" and "X--" decrement the value of X by 11.

Return the final value of X after executing all the operations in operations.

Constraints:

  • 1≤1 \leq operations.length ≤100\leq 100

  • operations[i] will be either "++X", "X++", "--X", or "X--".

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Final Value of Variable After Performing Operations

med
30 min
Try to solve the Final Value of Variable After Performing Operations problem.

Statement

There is a single variable X that initially has a value of 00.

You are given an array of strings operations containing operations that modify the value of X:

  • "++X" and "X++" increment the value of X by 11.

  • "--X" and "X--" decrement the value of X by 11.

Return the final value of X after executing all the operations in operations.

Constraints:

  • 1≤1 \leq operations.length ≤100\leq 100

  • operations[i] will be either "++X", "X++", "--X", or "X--".