1963. Minimum Number of Swaps to Make the String Balanced

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1963

class Solution:
    def minSwaps(self, s: str) -> int:
        x = 0
        for c in s:
            if c == "[":
                x += 1
            elif x:
                x -= 1
        return (x + 1) >> 1