Minimum Number of Swaps to Make the String Balanced LeetCode solution in Python

1
class Solution:
2
def minSwaps(self, s: str) -> int:
3
res, bal = 0, 0
4
for ch in s:
5
bal += 1 if ch == "[" else -1
6
if bal == -1:
7
res += 1
8
bal = 1
9
return res

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0