package leetcode;

/**
 * https://leetcode.com/problems/minimum-swaps-to-make-strings-equal/
 */
public class Problem1247 {
    public int minimumSwap(String s1, String s2) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1247 prob = new Problem1247();
        System.out.println(prob.minimumSwap("xx", "yy")); // 1
        System.out.println(prob.minimumSwap("xy", "yx")); // 2
        System.out.println(prob.minimumSwap("xx", "xy")); // -1
        System.out.println(prob.minimumSwap("xxyyxyxyxx", "xyyxyxxxyx")); // 4
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashSet;%0Aimport java.util.Set;%0A%0A
 /**%0A * h
@@ -229,32 +229,1307 @@
     
-// TODO%0A        return 0
+Set%3CInteger%3E xSet = new HashSet%3C%3E();%0A        Set%3CInteger%3E ySet = new HashSet%3C%3E();%0A        for (int i = 0; i %3C s1.length(); i++) %7B%0A            if (s1.charAt(i) != s2.charAt(i)) %7B%0A                if (s1.charAt(i) == 'x') %7B%0A                    xSet.add(i);%0A                %7D else %7B%0A                    ySet.add(i);%0A                %7D%0A            %7D%0A        %7D%0A        int answer = 0;%0A        for (int i = 0; i %3C s1.length(); i++) %7B%0A            if (s1.charAt(i) != s2.charAt(i)) %7B%0A                if (s1.charAt(i) == 'x') %7B%0A                    if (xSet.size() %3E 1) %7B%0A                        xSet.remove(i);%0A                        ySet.remove(i);%0A                        int index = xSet.iterator().next();%0A                        xSet.remove(index);%0A                        ySet.remove(index);%0A                        answer++;%0A                    %7D%0A                %7D else %7B%0A                    if (ySet.size() %3E 1) %7B%0A                        xSet.remove(i);%0A                        ySet.remove(i);%0A                        int index = ySet.iterator().next();%0A                        xSet.remove(index);%0A                        ySet.remove(index);%0A                        answer++;%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return xSet.isEmpty() && ySet.isEmpty() ? answer : -1
 ;%0A  

Update problem 1247