package leetcode;

/**
 * https://leetcode.com/problems/buddy-strings/
 */
public class Problem859 {
    public boolean buddyStrings(String A, String B) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem859 prob = new Problem859();
        System.out.println(prob.buddyStrings("ab", "ba")); // true
        System.out.println(prob.buddyStrings("ab", "ab")); // false
        System.out.println(prob.buddyStrings("aa", "aa")); // true
        System.out.println(prob.buddyStrings("aaaaaaabc", "aaaaaaacb")); // true
        System.out.println(prob.buddyStrings("", "aa")); // false
        System.out.println(prob.buddyStrings("abc", "cba")); // true
    }
}

@@ -160,15 +160,39 @@
     
-// TODO
+if (A.length() != B.length()) %7B
 %0A   
@@ -196,16 +196,20 @@
         
+    
 return f
@@ -214,16 +214,546 @@
  false;%0A
+        %7D%0A        int idx1 = 0;%0A        int idx2 = 0;%0A        int count = 0;%0A        for (int i = 0; i %3C A.length(); i++) %7B%0A            if (A.charAt(i) != B.charAt(i)) %7B%0A                if (count == 0) %7B%0A                    idx1 = i;%0A                %7D else if (count == 1) %7B%0A                    idx2 = i;%0A                %7D else %7B%0A                    return false;%0A                %7D%0A                count++;%0A            %7D%0A        %7D%0A        return (A.charAt(idx1) == B.charAt(idx2) &&%0A            A.charAt(idx2) == B.charAt(idx1));%0A
     %7D%0A%0A 
@@ -1181,32 +1181,32 @@
 aa%22)); // false%0A
-
         System.o
@@ -1254,20 +1254,158 @@
 )); // true%0A
+        System.out.println(prob.buddyStrings(%22aab%22, %22aab%22)); // true%0A        System.out.println(prob.buddyStrings(%22aba%22, %22aba%22)); // true%0A
     %7D%0A%7D%0A

Update problem 859