C++ Two Pointer Solution.
Idea\nFind the first unpaired right bracket from the left side, and Find the first unpaired left bracket from the right side, then swap left and right character
### Idea\nFind the first unpaired right bracket from the left side, and Find the first unpaired left bracket from the right side, then swap left and right character.\n\n```\nclass Solution {\npublic:\n    int ans = 0;\n    int minSwaps(string s) {\n        int cnt = 0;\n        int l = 0, r = s.size() - 1;\n        while(l < r) {\n            int cnt = 0;\n            while(l < s.size()) {\n                cnt += s[l] == \'[\' ? 1 : -1;\n                if(cnt < 0) break;\n                l++;\n            }\n            \n            cnt = 0;\n            while(r >= 0) {\n                cnt += s[r] == \'[\' ? 1 : -1;\n                if(cnt > 0) break;\n                r--;\n            }\n            if(r >= 0 && l < s.size()) {\n                swap(s[l], s[r]);\n                ++ans;\n            }\n        }\n        return ans;\n    }\n};\n```\n
[]