-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsomorphic.java
More file actions
29 lines (24 loc) · 814 Bytes
/
Isomorphic.java
File metadata and controls
29 lines (24 loc) · 814 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
class Isomorphic {
public boolean isIsomorphic(String s, String t) {
if(s.length() != t.length())
return false;
HashMap<Character,Character> map1 = new HashMap<>();
HashMap<Character,Boolean> 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)==true){
if(map1.get(ch1) != ch2 )
return false;
}
else{
if(map2.containsKey(ch2)==true)
return false;
else{
map1.put(ch1,ch2);
map2.put(ch2, true); }
}
}
return true;
}
}