We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 60a2d93 commit cdfdea9Copy full SHA for cdfdea9
1 file changed
Strings/IsomorphicStrings.java
@@ -0,0 +1,27 @@
1
+class IsomorphicStrings {
2
+ public boolean isIsomorphic(String s, String t) {
3
+ Map<Character, Character> map1 = new TreeMap<>();
4
+ Map<Character, Character> map2 = new TreeMap<>();
5
+
6
+ if(s.length() != t.length()){
7
+ return false;
8
+ }
9
10
+ for(int i = 0; i<s.length(); i++){
11
+ if(!map1.containsKey(s.charAt(i))){
12
+ map1.put(s.charAt(i), t.charAt(i));
13
14
+ if(map1.get(s.charAt(i)) != t.charAt(i)){
15
16
17
+ if(!map2.containsKey(t.charAt(i))){
18
+ map2.put(t.charAt(i), s.charAt(i));
19
20
+ if(map2.get(t.charAt(i)) != s.charAt(i)){
21
22
23
24
25
+ return true;
26
27
+}
0 commit comments