Skip to content

Commit 775606f

Browse files
authored
Merge pull request neetcode-gh#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
Lines changed: 15 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy