100%
难以理解的答案:
public class Solution {
public bool IsIsomorphic(string s, string t) {
int counter = 1;
var dictS = new int[127];
var dictT = new int[127];
for (int i = 0; i < s.Length; i++)
{
if (dictS[s[i]] != dictT[t[i]])
return false;
else if (dictS[s[i]] == 0)
{
dictS[s[i]] = dictT[t[i]] = counter;
counter++;
}
}
return true;
}
}
转载的dictionary:
public static void Main(string[] args)
{
string s = "egg", t = "add";
bool c=IsIsomorphic(s, t);
Console.WriteLine(c);
Console.ReadKey();
}
public static bool IsIsomorphic(string s, string t)
{
var dic = new Dictionary<int, int>();
for (int i = 0; i < s.Length; i++)
{
if (!dic.ContainsKey(s[i]))
{
if (dic.ContainsValue(t[i])) return false;
dic[s[i]] = t[i];
}
}
for (int i = 0; i < s.Length; i++)
{
if (dic[s[i]]!=t[i]) return false;
}
return true;
}
转载自:https://blog.csdn.net/qq_31116753/article/details/82670997