Beats 45% using stack
Intuition\n Stacks , Greedy \n\n# Approach\nusing stacks to solve the problem using basic maths and logic \n\n# Complexity\n- Time complexity:\n  o(n)\n\n- Spac
# Intuition\n Stacks , Greedy \n\n# Approach\nusing stacks to solve the problem using basic maths and logic \n\n# Complexity\n- Time complexity:\n  o(n)\n\n- Space complexity:\n O(n)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minSwaps(string s) {\n        stack<char>st;\n        for(int i=0;i<s.size();i++){\n            if(!st.empty() && st.top()==\'[\' && s[i]==\']\'){\n                st.pop();\n            }\n            else{\n                st.push(s[i]);\n            }\n        }\n        int open =0;\n        int ans=0;\n        int close =0;\n        int size =st.size();\n        while(!st.empty()){\n            if(st.top()==\'[\'){\n\n                open++;\n            }\n            else{\n                close++;\n            }\n            st.pop();\n        }\n\n           if(open==0)ans =0;\n          else if(open==1)ans = 1;\n           else if(open>=2)ans= open%2==0 ? open/2:open/2+1;\n        \n        return ans;\n    }\n};\n```
['C++']