-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
23 lines (19 loc) · 742 Bytes
/
Copy pathsolution.java
File metadata and controls
23 lines (19 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public boolean isIsomorphic(String s, String t) {
int[] smap = new int[128]; //Storing char to char by ascii number
int[] tmap = new int[128]; //Storing reverse mapping for above map
for(int i = 0; i < s.length(); i++){
int chS = s.charAt(i), chT = t.charAt(i);
//If mapping not found then create one
if(smap[chS] == 0 && tmap[chT] == 0) {
smap[chS] = chT;
tmap[chT] = chS;
continue;
}
//If one of the mapping doesn't match
if(smap[chS] != chT || tmap[chT] != chS)
return false;
}
return true;
}
}