Skip to content

Commit ba0f67a

Browse files
Create: 1963-min-number-of-swaps.rs
1 parent 36d75f8 commit ba0f67a

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+
impl Solution {
2+
pub fn min_swaps(s: String) -> i32 {
3+
let mut extra_close = 0;
4+
let mut max_close = 0;
5+
6+
for c in s.chars() {
7+
if c == '[' {
8+
extra_close -= 1;
9+
} else {
10+
extra_close += 1;
11+
}
12+
13+
max_close = max_close.max(extra_close);
14+
}
15+
16+
(max_close + 1) / 2
17+
}
18+
}

0 commit comments

Comments
 (0)