Skip to content

Commit a008f65

Browse files
authored
Update minimum-number-of-swaps-to-make-the-string-balanced.cpp
1 parent 4378e7b commit a008f65

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

C++/minimum-number-of-swaps-to-make-the-string-balanced.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ class Solution {
66
int minSwaps(string s) {
77
int result = 0, curr = 0;
88
for (const auto& c : s) {
9-
curr = (c == ']') ? curr + 1 : curr - 1;
10-
result = max(result, curr);
9+
if (c == ']') {
10+
++curr;
11+
result = max(result, curr);
12+
} else {
13+
--curr;
14+
}
1115
}
1216
return (result + 1) / 2;
1317
}

0 commit comments

Comments
 (0)