Skip to content

Commit

Permalink
Create: 0205-isomorphic-strings.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprudhomme committed Jan 9, 2023
1 parent fa2d4c3 commit 0e9a876
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions csharp/0205-isomorphic-strings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
}

0 comments on commit 0e9a876

Please sign in to comment.