Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1979 from alexprudhomme/0205-isomorphi…
Browse files Browse the repository at this point in the history
…c-strings.cs

Create: 0205-isomorphic-strings.cs
  • Loading branch information
tahsintunan authored Jan 10, 2023
2 parents 9670149 + 0e9a876 commit 9e0f788
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 9e0f788

Please sign in to comment.