diff --git a/csharp/0205-isomorphic-strings.cs b/csharp/0205-isomorphic-strings.cs new file mode 100644 index 000000000..04097c6a8 --- /dev/null +++ b/csharp/0205-isomorphic-strings.cs @@ -0,0 +1,29 @@ +public class Solution { + public bool IsIsomorphic(string s, string t) { + Dictionary mapST = new Dictionary(); + Dictionary mapTS = new Dictionary(); + + 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; + } +} \ No newline at end of file