Skip to content

Commit 1cae143

Browse files
author
Jinyue Xia
committed
test git
1 parent 1409b67 commit 1cae143

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Easy/205-isomorphicStrings.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,20 @@ Object.prototype.getKeyByValue = function(value) {
3838
}
3939
}
4040
};
41+
42+
// a better solution, use array
43+
var isIsomorphic = function(s, t) {
44+
var arrS = [],
45+
arrT = [];
46+
47+
for (var i = 0; i < s.length; i++) {
48+
if (arrS[s.charCodeAt(i)] !== arrT[t.charCodeAt(i)]) {
49+
return false;
50+
}
51+
52+
arrS[s.charCodeAt(i)] = i;
53+
arrT[t.charCodeAt(i)] = i;
54+
}
55+
56+
return true;
57+
};

0 commit comments

Comments
 (0)