forked from neetcode-gh/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0205-isomorphic-strings.cs
More file actions
29 lines (25 loc) · 838 Bytes
/
0205-isomorphic-strings.cs
File metadata and controls
29 lines (25 loc) · 838 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
public class Solution {
public bool IsIsomorphic(string s, string t) {
Dictionary<string, string> mapST = new Dictionary<string, string>();
Dictionary<string, string> mapTS = new Dictionary<string, string>();
for (int i = 0; i < s.Length; i++) {
string sChar = s[i].ToString();
string tChar = t[i].ToString();
if (mapST.ContainsKey(sChar)) {
if (mapST[sChar] != tChar) {
return false;
}
} else {
mapST.Add(sChar, tChar);
}
if (mapTS.ContainsKey(tChar)) {
if (mapTS[tChar] != sChar) {
return false;
}
} else {
mapTS.Add(tChar, sChar);
}
}
return true;
}
}