2025-08-16 14:05:37 +0300 MSK

Final Value of Variable After Performing Operations

Code

class Solution:
    def finalValueAfterOperations(self, operations: List[str]) -> int:
        res = 0
        for op in operations:
            if op.startswith("++") or op.endswith("++"):
                res += 1
            else:
                res -= 1
        return res