package leetcode;

/**
 * https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal/
 */
public class Problem1790 {
    public boolean areAlmostEqual(String s1, String s2) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem1790 prob = new Problem1790();
        System.out.println(prob.areAlmostEqual("bank", "kanb")); // true
        System.out.println(prob.areAlmostEqual("attack", "defend")); // false
        System.out.println(prob.areAlmostEqual("kelb", "kelb")); // true
        System.out.println(prob.areAlmostEqual("abcd", "dcba")); // false
    }
}

@@ -199,208 +199,502 @@
     
-// TODO%0A        return false;%0A
+int count = 0;%0A        int index1 = -1;%0A        int index2 = -1;%0A        for (int i = 0; i %3C s1.length(); i++) %7B%0A  
     
-%7D%0A%0A
+  
     
-public static void main(String%5B%5D args) %7B%0A        Problem1790 prob = new Problem1790();%0A        System.out.println(prob.areAlmostEqual(%22bank%22, %22kanb%22)); //
+if (s1.charAt(i) != s2.charAt(i)) %7B%0A                if (index1 == -1) %7B%0A                    index1 = i;%0A                %7D else if (index2 == -1) %7B%0A                    index2 = i;%0A                %7D%0A                count++;%0A            %7D%0A            if (count %3E 2) %7B%0A                return false;%0A            %7D%0A        %7D%0A        if (count == 0) %7B%0A            return
  true
+;
 %0A   
@@ -702,77 +702,61 @@
     
-System.out.println(prob.areAlmostEqual(%22attack%22, %22defend%22)); //
+%7D%0A        if (count != 2) %7B%0A            return
  false
+;
 %0A   
@@ -764,146 +764,181 @@
     
-System.out.println(prob.areAlmostEqual(%22kelb%22, %22kelb%22)); // true%0A        System.out.println(prob.areAlmostEqual(%22abcd%22, %22dcba%22)); // false
+%7D%0A        char%5B%5D chars = s2.toCharArray();%0A        chars%5Bindex1%5D = s2.charAt(index2);%0A        chars%5Bindex2%5D = s2.charAt(index1);%0A        return s1.equals(new String(chars));
 %0A   

Solve problem 1790