Check if One String Swap Can Make Strings Equal

给两个string, 求是否可以通过一次交换, 使得两个string相同.

用个list存不同的index, 然后check. 注意开始的时候可以通过2个string的长度判断一下.

class Solution {
    public boolean areAlmostEqual(String s1, String s2) {
        if(s1.equals(s2))
            return true;
        if(s1.length() != s2.length())
            return false;
        int n = s1.length();
        List<Integer> list = new ArrayList<>();
        for(int i = 0 ; i < n; i++) {
            if(s1.charAt(i) != s2.charAt(i)){
                list.add(i);
            }
        }
        if(list.size() == 0)// all same
            return true;
        if(list.size() != 2)// only 2 different 
            return false;
        return s1.charAt(list.get(0)) == s2.charAt(list.get(1)) && s1.charAt(list.get(1)) == s2.charAt(list.get(0));// check the 2 different
    }
}