- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNo205.java
31 lines (29 loc) · 643 Bytes
/
No205.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
packageAlgorithm.leetcode.String;
importjava.util.HashMap;
importjava.util.Map;
publicclassNo205 {
publicbooleanisIsomorphic(Strings, Stringt) {
if (s.length() <= 1 || s == null) {
returntrue;
}
Map<Character, Character> hashMap = newHashMap<Character, Character>();
for (inti = 0; i < s.length(); i++) {
chara = s.charAt(i);
charb = t.charAt(i);
if (hashMap.containsKey(a)) {
if (hashMap.get(a).equals(b)) {
continue;
} else {
returnfalse;
}
} else {
if (!hashMap.containsValue(b)) {
hashMap.put(a, b);
} else {
returnfalse;
}
}
}
returntrue;
}
}