Isomorphic Strings LeetCode solution in JavaScript

1
/**
2
* @param {string} s
3
* @param {string} t
4
* @return {boolean}
5
*/
6
var isIsomorphic = function (s, t) {
7
const obj = {};
8
const setValues = new Set();
9
let isIso = true;
10

11
for (var indexI = 0; indexI < s.length; indexI++) {
12
if (obj[s[indexI]] || setValues.has(t[indexI])) {
13
if (obj[s[indexI]] === t[indexI]) continue;
14

15
isIso = false;
16
break;
17
} else {
18
obj[s[indexI]] = t[indexI];
19
setValues.add(t[indexI]);
20
}
21
}
22

23
return isIso;
24
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0