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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 17.7MB, accepted 2025-12-27.
class Solution {
public:
int finalValueAfterOperations(vector<string>& operations) {
int x = 0;
for (auto& op : operations) {
x += (op[1] == '+') ? 1 : -1;
}
return x;
}
};