class Solution:
def minSwaps(self, s: str) -> int:
stack = []
for c in s:
if c == '[':
stack.append(c)
elif stack:
stack.pop()
return (len(stack) + 1) // 2class Solution:
def minSwaps(self, s: str) -> int:
close = maxClose = 0
for c in s:
if c == '[':
close -= 1
else:
close += 1
maxClose = max(maxClose, close)
return (maxClose + 1) // 2class Solution:
def minSwaps(self, s: str) -> int:
stackSize = 0
for c in s:
if c == '[':
stackSize += 1
elif stackSize > 0:
stackSize -= 1
return (stackSize + 1) // 2