Skip to content

Commit 73e9fb8

Browse files
Create 1963. Minimum Number of Swaps to Make the String Balanced.cpp
1 parent beec778 commit 73e9fb8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int minSwaps(string s) {
4+
int n = s.size();
5+
6+
stack<char>st;
7+
8+
for(auto c : s ){
9+
if(c == '[' ){
10+
st.push(c);
11+
}
12+
if(c == ']'){
13+
if(st.size() > 0){
14+
st.pop();
15+
}
16+
}
17+
}
18+
19+
int ans = (st.size()+1)/2;
20+
return ans;
21+
}
22+
};

0 commit comments

Comments
 (0)