My Java solution 0ms
\n\nclass Solution {\n    public boolean areAlmostEqual(String s1, String s2) {\n        List<Integer> l = new ArrayList<>();\n        for (int i = 0; i < s1.le
\n```\nclass Solution {\n    public boolean areAlmostEqual(String s1, String s2) {\n        List<Integer> l = new ArrayList<>();\n        for (int i = 0; i < s1.length(); i++) {\n            if (s1.charAt(i) != s2.charAt(i)) l.add(i);\n\t\t\tif (l.size() > 2) return false; // added this line to short circuit the loop\n        }\n        return l.size() == 0 || (l.size() == 2\n                                 && s1.charAt(l.get(0)) == s2.charAt(l.get(1))\n                                 && s1.charAt(l.get(1)) == s2.charAt(l.get(0)));\n    }\n}\n```\n\nNote: added a short circuit in the for loop although it won\'t reduce the execution time for the test cases.
[]