-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsomorphicStrings.java
More file actions
29 lines (26 loc) · 1014 Bytes
/
IsomorphicStrings.java
File metadata and controls
29 lines (26 loc) · 1014 Bytes
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
//205. Isomorphic Strings
class Solution {
public boolean isIsomorphic(String s, String t) {
int[] mapST = new int[256];
int[] mapTS = new int[256];
for(int i=0;i<s.length();i++){
if(mapST[s.charAt(i)] != mapTS[t.charAt(i)]) return false;
mapST[s.charAt(i)]=i+1;
mapTS[t.charAt(i)]=i+1;
}
return true;
}
}
// class Solution {
// public boolean isIsomorphic(String s, String t) {
// HashMap<Character, Character> maps = new HashMap<>();
// HashMap<Character, Character> mapt = new HashMap<>();
// for(int i=0;i<s.length();i++){
// if(!maps.containsKey(s.charAt(i))) maps.put(s.charAt(i),t.charAt(i));
// else if (maps.get(s.charAt(i)) != t.charAt(i)) return false;
// if(!mapt.containsKey(t.charAt(i))) mapt.put(t.charAt(i),s.charAt(i));
// else if (mapt.get(t.charAt(i)) != s.charAt(i)) return false;
// }
// return true;
// }
// }