-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path205.dart
35 lines (31 loc) · 816 Bytes
/
205.dart
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
class Solution {
bool isIsomorphic(String s, String t) {
if (s.length != t.length) {
return false;
} else {
Map<String, String> st = {};
Map<String, String> ts = {};
for (int i = 0 ; i<s.length ; i++) {
String charS = s[i];
String charT = t[i];
// s->t
if (st.containsKey(charS)) {
if (st[charS] != charT) {
return false;
}
} else {
st[charS] = charT;
}
// t->s
if (ts.containsKey(charT)) {
if (ts[charT] != charS) {
return false;
}
} else {
ts[charT] = charS;
}
}
return true;
}
}
}