Variable After Commands

Imagine a variable X that starts at 0 and then receives short commands to increase or decrease it. Write a function final_value that processes the list operations. The operations "++X" and "X++" add 1, while "--X" and "X--" subtract 1. Return the final value of X after all commands are applied.

Примеры

Ввод
["--X", "X++", "X++"]
Вывод
1
Ввод
["++X", "++X", "X++"]
Вывод
3
Ввод
["X++", "++X", "--X", "X--"]
Вывод
0

Нужно реализовать

def final_value(operations: list[str]) -> int:

Теги

stringsarray
PostgreSQLv16

Aici va apărea rezultatul execuției codului

Visible tests
1
Input
["--X","X++","X++"]
Expected1
2
Input
["++X","++X","X++"]
Expected3
3
Input
["X++","++X","--X","X--"]
Expected0
4
Input
[]
Expected0
5
Input
["--X"]
Expected-1
6
Input
["X++","X++","X++"]
Expected3
Focus radio
Paused · SomaFM · Fluid