-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSolution.js
44 lines (38 loc) · 927 Bytes
/
Solution.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// https://leetcode.com/problems/isomorphic-strings/
/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
// both functions are working
var isIsomorphic = function (s, t) {
const tbl = {}, trkr = {}
for (let i = 0; i < is.length; i++) {
if (!(s[i] in tbl) && !(t[i] in trkr)) {
tbl[s[i]] = t[i]
trkr[t[i]] = s[i]
} else {
if (tbl[s[i]] !== t[i]) return false;
}
}
return true
};
// 76%
// 26 line removal get 96%
var isIsomorphic2 = function (s, t) {
let a = {};
let b = {};
if (s.length != t.length) return false;
for (i = 0; i < s.length; i++) {
if (!(s[i] in a) && !(t[i] in b)) {
a[s[i]] = t[i];
b[t[i]] = s[i];
} else {
if (a[s[i]] != t[i]) return false;
}
}
return true;
};
let s = "egg";
let t = "add";
console.log(isIsomorphic(s, t));