Initial commit
This commit is contained in:
11
205. Isomorphic Strings/205. Isomorphic Strings.csproj
Normal file
11
205. Isomorphic Strings/205. Isomorphic Strings.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>_205._Isomorphic_Strings</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
10
205. Isomorphic Strings/Program.cs
Normal file
10
205. Isomorphic Strings/Program.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace _205._Isomorphic_Strings
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(new Solution().IsIsomorphic("egg","foo"));
|
||||
}
|
||||
}
|
||||
}
|
||||
37
205. Isomorphic Strings/Solution.cs
Normal file
37
205. Isomorphic Strings/Solution.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _205._Isomorphic_Strings;
|
||||
|
||||
public class Solution
|
||||
{
|
||||
public bool IsIsomorphic(string s, string t)
|
||||
{
|
||||
Dictionary<char, char> table = new Dictionary<char, char>();
|
||||
Dictionary<char, char> antiTable = new Dictionary<char, char>();
|
||||
for(int i = 0; i < s.Length; i++)
|
||||
{
|
||||
char source = s[i];
|
||||
char to = t[i];
|
||||
if (table.ContainsKey(source))
|
||||
{
|
||||
if(table[source] != to)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
table.Add(source, to);
|
||||
|
||||
if (antiTable.ContainsKey(to))
|
||||
{
|
||||
if (antiTable[to] != source)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
antiTable.Add(to, source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user