Skip to content

Commit

Permalink
Create 1963. Minimum Number of Swaps to Make the String Balanced (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Oct 8, 2024
2 parents c96b900 + d47f6b6 commit eff2af5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 1963. Minimum Number of Swaps to Make the String Balanced
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public:
int minSwaps(string s) {
int maxiClose=0;
int maxi=0;
for(int i=0;i<s.size();i++){
if(s[i]=='['){
maxiClose--;
}
else{
maxiClose++;
}
maxi=max(maxiClose,maxi);

}
return (maxi+1)/2;

}
};

0 comments on commit eff2af5

Please sign in to comment.