deno.land / x / masx200_leetcode_test@10.6.5 / check-if-one-string-swap-can-make-strings-equal / index.ts
12345678910111213141516171819export default function areAlmostEqual(s1: string, s2: string): boolean { if (s1 === s2) return true;
let d1 = ""; let d2 = "";
for (let i = 0; i < s1.length; i++) { const ch1 = s1[i]; const ch2 = s2[i];
if (ch1 !== ch2) { d1 += ch1; d2 = ch2 + d2; } if (d1.length > 2) return false; } return d1.length === 2 && d1 === d2;}
Version Info