deno.land / x / masx200_leetcode_test@10.6.5 / check-if-one-string-swap-can-make-strings-equal / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
export 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;}
masx200_leetcode_test

Version Info

Tagged at
a year ago