LeetCode solutions

2137. Final Value of Variable After Performing Operations

My accepted C++ solution to LeetCode problem 2137, Final Value of Variable After Performing Operations, running in 0ms.

  • Difficulty: Easy
  • C++
  • Runtime 0ms
  • Memory 17.7MB

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 17.7MB, accepted 2025-12-27.

cpp
class Solution {
    public:
    int finalValueAfterOperations(vector<string>& operations) {
        int x = 0;
        for (auto& op : operations) {
            x += (op[1] == '+') ? 1 : -1;
        }
        return x;
    }
};

Source