Skip to content

Commit a93ccfe

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

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def minSwaps(self, s: str) -> int:
3+
extraClose, maxClose = 0, 0
4+
5+
for c in s:
6+
if c == "[":
7+
extraClose -= 1
8+
else:
9+
extraClose += 1
10+
11+
maxClose = max(maxClose, extraClose)
12+
13+
return (maxClose + 1) // 2 # Or math.ceil(maxClose / 2)

0 commit comments

Comments
 (0)