Skip to content

Commit 614dcf1

Browse files
authoredOct 8, 2024
1963. Minimum number of Swaps to make String Balanced.cpp
1 parent 947e9a4 commit 614dcf1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// ************************************* C++ *************************************
2+
3+
T.C - O(n)
4+
5+
6+
int minSwaps(string s) {
7+
int size = 0;
8+
9+
for(char &ch : s) {
10+
if(ch == '[')
11+
size++;
12+
else if(size != 0)
13+
size--;
14+
}
15+
16+
return (size+1)/2;
17+
}
18+
};

0 commit comments

Comments
 (0)
Please sign in to comment.