-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsomorphic_Strings.java
More file actions
32 lines (31 loc) · 861 Bytes
/
Isomorphic_Strings.java
File metadata and controls
32 lines (31 loc) · 861 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
import java.util.*;
import java.io.*;
import java.lang.*;
public class Isomorphic_Strings {
class Solution {
public boolean isIsomorphic(String s, String t)
{
int n = s.length();
HashMap<Character , Character> hm = new HashMap<>();
for(int i = 0 ; i<n ; i++)
{
if(!hm.containsKey(s.charAt(i)))
{
if(hm.containsValue(t.charAt(i)))
{
return false;
}
hm.put(s.charAt(i) , t.charAt(i));
}
else
{
if(hm.get(s.charAt(i)) != t.charAt(i))
{
return false;
}
}
}
return true;
}
}
}