-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisIsomorphic.java
More file actions
48 lines (39 loc) · 1.27 KB
/
isIsomorphic.java
File metadata and controls
48 lines (39 loc) · 1.27 KB
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
45
46
47
import java.util.HashMap;
import java.util.Map;
/**
* Author : WindAsMe
* File : isIsomorphic.java
* Time : Create on 18-6-4
* Location : ../Home/JavaForLeeCode2/isIsomorphic.java
* Function : LeeCode No.205
*/
public class isIsomorphic {
private static boolean isIsomorphicResult(String s, String t) {
Map<Character, Integer> mapS = new HashMap<>();
Map<Character, Integer> mapT = new HashMap<>();
int[] indexS = new int[s.length()];
int[] indexT = new int[t.length()];
for (int i = 0 ; i < s.length() ; i ++ ){
char tempS = s.charAt(i);
char tempT = t.charAt(i);
if (mapS.get(tempS) == null){
mapS.put(tempS, i);
indexS[i] = i;
} else
indexS[i] = mapS.get(tempS);
if (mapT.get(tempT) == null){
mapT.put(tempT, i);
indexT[i] = i;
} else
indexT[i] = mapT.get(tempT);
}
for (int i = 0 ; i < t.length() ; i ++ ){
if (indexS[i] != indexT[i])
return false;
}
return true;
}
public static void main(String[] args) {
System.out.println(isIsomorphicResult("egga", "addd"));
}
}