-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisomorphic.java
More file actions
43 lines (42 loc) · 901 Bytes
/
isomorphic.java
File metadata and controls
43 lines (42 loc) · 901 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
36
37
38
39
40
41
42
43
import java.util.HashMap;
public class isomorphic
{
public static void main(String[]args)
{
String s="paper";
String t="title";
System.out.println(isisomorphic(s,t));
}
public static boolean isisomorphic(String s, String t)
{
HashMap<Character,Character>map=new HashMap<>();
if(s.length()!=t.length())
{
return false;
}
for(int i=0;i<s.length();i++)
{
char o=s.charAt(i);
char r=t.charAt(i);
if(!map.containsKey(o))
{
if(!map.containsValue(r))
{
map.put(o, r);
}
else{
return false;
}
}
else
{
char mapch= map.get(o);
if(mapch!=r)
{
return false;
}
}
}
return true;
}
}