forked from super30admin/Hashing-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem2_Array.java
39 lines (36 loc) · 1.07 KB
/
Problem2_Array.java
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
// Time Complexity : O(N)
// Space Complexity : O(1)
// Did this code successfully run on Leetcode : Yes
// Any problem you faced while coding this : No
class Solution {
public boolean isIsomorphic(String s, String t) {
if(s==null && t==null){
return true;
}else if(s==null || t==null){
return false;
}
char[] sChar = new char[256];
char[] tChar = new char[256];
for(int i=0;i<s.length();i++){
Character key = s.charAt(i);
Character value = t.charAt(i);
if(sChar[key-' ']==0){
sChar[key-' '] = value;
}else{
if(sChar[key-' ']!=value)
return false;
}
}
for(int i=0;i<t.length();i++){
Character key = t.charAt(i);
Character value = s.charAt(i);
if(tChar[key-' ']==0){
tChar[key-' '] = value;
}else{
if(tChar[key-' ']!=value)
return false;
}
}
return true;
}
}