package leetcode;

/**
 * https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-string-balanced/
 */
public class Problem1963 {
    public int minSwaps(String s) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1963 prob = new Problem1963();
        System.out.println(prob.minSwaps("][][")); // 1
        System.out.println(prob.minSwaps("]]][[[")); // 2
        System.out.println(prob.minSwaps("[]")); // 0
    }
}

@@ -181,299 +181,899 @@
     
-// TODO%0A        return 0;%0A
+char%5B%5D chars = s.toCharArray();%0A        int%5B%5D openIndexes = new int%5Bs.length() / 2%5D;%0A        int j = 0;%0A        for (int i = 0; i %3C s.length(); i++) %7B%0A  
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1963 prob = new Problem1963();%0A        System.out.println(prob.minSwaps(%22%5D%5B%5D%5B%22)); // 1%0A        System.out.println(prob.minSwaps(%22%5D%5D%5D%5B%5B%5B%22)); // 2%0A        System.out.println(prob.minSwaps(%22%5B%5D%22)); // 0
+ if (s.charAt(i) == '%5B') %7B%0A               openIndexes%5Bj++%5D = i;%0A           %7D%0A        %7D%0A        int answer = 0;%0A        int numOpen = 0;%0A        int openIndex = openIndexes.length - 1;%0A        for (int i = 0; i %3C s.length(); i++) %7B%0A            if (s.charAt(i) == '%5B') %7B%0A                numOpen++;%0A            %7D else %7B%0A                if (numOpen - 1 %3C 0) %7B%0A                    char tmp = chars%5Bi%5D;%0A                    chars%5Bi%5D = chars%5BopenIndexes%5BopenIndex%5D%5D;%0A                    chars%5BopenIndexes%5BopenIndex%5D%5D = tmp;%0A                    openIndex--;%0A                    numOpen++;%0A                    answer++;%0A                %7D else %7B%0A                    numOpen--;%0A                %7D%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1963