[Python3] greedy
\n\nclass Solution:\n    def minSwaps(self, s: str) -> int:\n        ans = prefix = 0 \n        for ch in s:\n            if ch == "[": prefix += 1\n           
\n```\nclass Solution:\n    def minSwaps(self, s: str) -> int:\n        ans = prefix = 0 \n        for ch in s:\n            if ch == "[": prefix += 1\n            else: prefix -= 1\n            if prefix == -1:\n                ans += 1\n                prefix = 1\n        return ans\n```\n\nThe solutions for weekly 255 can be found in this [commit](https://github.com/gaosanyong/leetcode/commit/312849ed66e5ad76fa278cbb34dd57772fb3ceeb).
['Python3']