Skip to content

Commit

Permalink
Create 1963-minimum-number-of-swaps-to-make-the-string-balanced.py
Browse files Browse the repository at this point in the history
Create the Python solution as the same solution in the YouTube video "https://www.youtube.com/watch?v=3YDBT9ZrfaU"
  • Loading branch information
MHamiid authored Jan 20, 2023
1 parent a651870 commit a93ccfe
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions python/1963-minimum-number-of-swaps-to-make-the-string-balanced.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
def minSwaps(self, s: str) -> int:
extraClose, maxClose = 0, 0

for c in s:
if c == "[":
extraClose -= 1
else:
extraClose += 1

maxClose = max(maxClose, extraClose)

return (maxClose + 1) // 2 # Or math.ceil(maxClose / 2)

0 comments on commit a93ccfe

Please sign in to comment.