-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode205.java
More file actions
35 lines (34 loc) · 974 Bytes
/
leetcode205.java
File metadata and controls
35 lines (34 loc) · 974 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
30
31
32
33
34
35
import java.util.*;
public class leetcode205 {
public static boolean isIsomorphic(String s, String t) {
if(s.length()!=t.length()){
return false;
}
HashMap<Character,Character> map1=new HashMap<>();
HashMap<Character,Character> map2=new HashMap<>();
for(int i=0;i<s.length();i++){
char ch1=s.charAt(i);
char ch2=t.charAt(i);
if(map1.containsKey(ch1)){
if(map1.get(ch1)!=ch2){
return false;
}
}
else{
map1.put(ch1,ch2);
}
if(map2.containsKey(ch2)){
if(map2.get(ch2)!=ch1){
return false;
}
}
else{
map2.put(ch2,ch1);
}
}
return true;
}
public static void main(String[] args) {
System.out.println(isIsomorphic("bat","hrr"));
}
}