Skip to content

Commit 0e9a876

Browse files
committed
Create: 0205-isomorphic-strings.cs
1 parent fa2d4c3 commit 0e9a876

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

csharp/0205-isomorphic-strings.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class Solution {
2+
public bool IsIsomorphic(string s, string t) {
3+
Dictionary<string, string> mapST = new Dictionary<string, string>();
4+
Dictionary<string, string> mapTS = new Dictionary<string, string>();
5+
6+
for (int i = 0; i < s.Length; i++) {
7+
string sChar = s[i].ToString();
8+
string tChar = t[i].ToString();
9+
10+
if (mapST.ContainsKey(sChar)) {
11+
if (mapST[sChar] != tChar) {
12+
return false;
13+
}
14+
} else {
15+
mapST.Add(sChar, tChar);
16+
}
17+
18+
if (mapTS.ContainsKey(tChar)) {
19+
if (mapTS[tChar] != sChar) {
20+
return false;
21+
}
22+
} else {
23+
mapTS.Add(tChar, sChar);
24+
}
25+
}
26+
27+
return true;
28+
}
29+
}

0 commit comments

Comments
 (0)