-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay 153.java
More file actions
34 lines (28 loc) · 832 Bytes
/
Day 153.java
File metadata and controls
34 lines (28 loc) · 832 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
class Solution {
public boolean areIsomorphic(String s1, String s2) {
if (s1.length() != s2.length()) {
return false;
}
int[] map = new int[26];
boolean[] used = new boolean[26];
for (int i = 0; i < 26; i++) {
map[i] = -1;
}
for (int i = 0; i < s1.length(); i++) {
int c1 = s1.charAt(i) - 'a';
int c2 = s2.charAt(i) - 'a';
if (map[c1] == -1) {
if (used[c2]) {
return false;
}
map[c1] = c2;
used[c2] = true;
} else {
if (map[c1] != c2) {
return false;
}
}
}
return true;
}
}