nikunjsoni

1963

Aug 15th, 2021
987
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     int minSwaps(string s) {
  4.         int open;
  5.         open = 0;
  6.         int minn=0;
  7.         for(auto c: s){
  8.             if(c == '[') open++;
  9.             if(c == ']') open--;
  10.             minn = min(open, minn);
  11.         }
  12.         if(minn >= 0) return 0;
  13.         minn = abs(minn);
  14.         return (minn+1)/2;
  15.     }
  16. };
RAW Paste Data