Skip to content

Commit 7c1f286

Browse files
committed
Create: 205-Isomorphic-Strings.ts
1 parent aa1fbd6 commit 7c1f286

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function isIsomorphic(s: string, t: string): boolean {
2+
const mapST = {};
3+
const mapTS = {};
4+
5+
for (let i = 0; i < s.length; i++) {
6+
let c1 = s[i];
7+
let c2 = t[i];
8+
9+
if ((mapST[c1] && mapST[c1] !== c2) || (mapTS[c2] && mapTS[c2] !== c1))
10+
return false;
11+
12+
mapST[c1] = c2;
13+
mapTS[c2] = c1;
14+
}
15+
16+
return true;
17+
}

0 commit comments

Comments
 (0)