Sharing my solution with O(n), O(1) and give clear explaination for everyone.
Approach\n Describe your approach to solving the problem. \n1. Count the unmatched closing brackets as unmatchedClosings\n2. Count the number of swap:\n    + If
## Approach\n<!-- Describe your approach to solving the problem. -->\n1. Count the unmatched closing brackets as `unmatchedClosings`\n2. Count the number of swap:\n    + If `unmatchedClosings` is odd, we have to swap once (`unmatchedClosings % 2`)\n        - Ex: `x]xxx[xx` -> `x[xxx]xx`\n    + And every 2 unmatched closing brackets, we must swap once (`unmatchedClosings // 2`), because we just swap the 2nd one, it will be self-balanced \n        - Ex: `]xxx[[xxxxx` -> `[xxx[]xxxxx` \n## Complexity\n- Time complexity: `O(n)`, where `n` is the length of string\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: `O(1)`\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n## Code\n```python3 []\nclass Solution:\n    def minSwaps(self, s: str) -> int:\n        # Count the unmatched closing brackets\n        unmatchedClosings = 0\n        for c in s:\n            if c == \'[\':\n                unmatchedClosings += 1\n            elif unmatchedClosings >= 1:\n                unmatchedClosings -= 1\n\n        return (unmatchedClosings % 2) + (unmatchedClosings // 2)\n```\n# Upvote if you find it helpful for everyone. Appreciate for your reading <3\n
['Python3']