-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsomorphic.java
More file actions
32 lines (30 loc) · 875 Bytes
/
Isomorphic.java
File metadata and controls
32 lines (30 loc) · 875 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
import java.util.Hashtable;
class iso{
public static void main(String[] args) {
Hashtable<Character, Character> ht = new Hashtable<Character, Character>();
String s = "egg";
String t = "add";
boolean flag = true;
for(int i=0; i<s.length(); i++){
if(ht.containsKey(s.charAt(i))){
if(ht.get(s.charAt(i)) != t.charAt(i)){
flag = false;
break;
}
}
else{
if(ht.containsValue(t.charAt(i))){
flag = false;
break;
}
ht.put(s.charAt(i), t.charAt(i));
}
}
if(flag){
System.out.println("Isomorphic");
}
else{
System.out.println("Not Isomorphic");
}
}
}