Skip to content

Commit eff2af5

Browse files
authored
Create 1963. Minimum Number of Swaps to Make the String Balanced (#608)
2 parents c96b900 + d47f6b6 commit eff2af5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
int minSwaps(string s) {
4+
int maxiClose=0;
5+
int maxi=0;
6+
for(int i=0;i<s.size();i++){
7+
if(s[i]=='['){
8+
maxiClose--;
9+
}
10+
else{
11+
maxiClose++;
12+
}
13+
maxi=max(maxiClose,maxi);
14+
15+
}
16+
return (maxi+1)/2;
17+
18+
}
19+
};

0 commit comments

Comments
 (0)