Skip to content

Commit 775606f

Browse files
authoredNov 9, 2024
Merge pull request #3090 from snghnaveen/go-1963
Create: 1963-minimum-number-of-swaps-to-make-the-string-balanced.go
2 parents 1f0ea7f + 93e981f commit 775606f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
func minSwaps(s string) int {
2+
close, maxClose := 0, 0
3+
for _, c := range s {
4+
if c == '[' {
5+
close += -1
6+
} else {
7+
close += +1
8+
}
9+
10+
if close > maxClose {
11+
maxClose = close
12+
}
13+
}
14+
return (maxClose + 1) / 2
15+
}

0 commit comments

Comments
 (0)
Please sign in to comment.