You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: solution/2000-2099/2011.Final Value of Variable After Performing Operations/README_EN.md
+8-32
Original file line number
Diff line number
Diff line change
@@ -83,11 +83,11 @@ X--: X is decremented by 1, X = 1 - 1 = 0.
83
83
84
84
<!-- solution:start -->
85
85
86
-
### Solution 1: Simulation
86
+
### Solution 1: Counting
87
87
88
-
Traverse the array `operations`. For each operation $operations[i]$, if it contains `'+'`, then the answer increases by $1$, otherwisethe answer decreases by $1$.
88
+
We traverse the array $\textit{operations}$. For each operation $\textit{operations}[i]$, if it contains `'+'`, we increment the answer by $1$, otherwise, we decrement the answer by $1$.
89
89
90
-
The time complexity is $O(n)$, where $n$ is the length of the array `operations`. The space complexity is $O(1)$.
90
+
The time complexity is $O(n)$, where $n$ is the length of the array $\textit{operations}$. The space complexity is $O(1)$.
91
91
92
92
<!-- tabs:start -->
93
93
@@ -120,7 +120,9 @@ class Solution {
120
120
public:
121
121
int finalValueAfterOperations(vector<string>& operations) {
122
122
int ans = 0;
123
-
for (auto& s : operations) ans += (s[1] == '+' ? 1 : -1);
0 commit comments