5 lines simple solution | C++ | beats 100%
Complexity\n- Time complexity: O(n)\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\npublic:\n    int minSwaps(string s) {\n        int open = 0;\n     
# Complexity\n- Time complexity: O(n)\n- Space complexity: O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int minSwaps(string s) {\n        int open = 0;\n        for(auto c: s){\n            if(c==\'[\') open++;\n            else if(open) open--;\n        }\n        return (open + 1)/2;\n    }\n};\n```
['C++']