Skip to content

Commit c56ebe5

Browse files
authored
Create 1963-minimum-number-of-swaps-to-make-the-string-balanced.c
Create the C solution as the same solution in the YouTube video "https://www.youtube.com/watch?v=3YDBT9ZrfaU"
1 parent a93ccfe commit c56ebe5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#define max(x, y) ((x) > (y) ? (x) : (y))
2+
3+
int minSwaps(char * s){
4+
int extraClosingBrackets = 0;
5+
int maxExtraClosingBrackets = 0;
6+
size_t sLen = strlen(s);
7+
8+
for(size_t i = 0; i < sLen; i++)
9+
{
10+
if(s[i] == ']')
11+
{
12+
extraClosingBrackets += 1;
13+
}
14+
else
15+
{
16+
extraClosingBrackets -= 1;
17+
}
18+
19+
maxExtraClosingBrackets = max(maxExtraClosingBrackets, extraClosingBrackets);
20+
}
21+
22+
return (maxExtraClosingBrackets + 1) / 2;
23+
}

0 commit comments

Comments
 (0)