You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
481 B
TypeScript
17 lines
481 B
TypeScript
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;
|
|
}
|