-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsomorphic Strings 9
33 lines (30 loc) · 993 Bytes
/
Isomorphic Strings 9
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
import java.io.*;
import java.util.*;
public class Solution {
public static boolean isIso(String str1 , String str2){
HashMap<Character,Character>map= new HashMap<>();
char c = 'a';
for(int i = 0 ; i < str1.length() ; i++){
if(map.containsKey(str1.charAt(i))){
c = map.get(str1.charAt(i));
if (c != str2.charAt(i))
return false;
}else if (!map.containsValue(str2.charAt(i))) {
map.put(str1.charAt(i),str2.charAt(i));
} else {
return false;
}
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str1 = sc.nextLine();
String str2 = sc.nextLine();
if(str1.length() == str2.length() && isIso(str1,str2)){
System.out.println("true");
}else{
System.out.println("false");
}
}
}