[HAI] isIsomorphic my solution

This commit is contained in:
2024-11-22 05:07:08 +03:00
parent 8e4c2c136e
commit 4c14d98644
4 changed files with 104 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
export function isIsomorphic(s: string, t: string): boolean {
let ht: Record<string, string> = {};
let ht2: Record<string, string> = {};
if (s.length !== t.length) return false;
for (let [index, key] of Object.entries(s)) {
const currentValue = t[index];
if (key in ht && currentValue !== ht[key]) return false;
if (currentValue in ht2 && key !== ht2[currentValue]) return false;
ht[key] = currentValue;
ht2[currentValue] = key;
}
return true;
}