public class Solution {
public bool IsIsomorphic(string s, string t) {
if (s.Length != t.Length)
{
return false;
}
else
{
Dictionary<char, int> dic1 = new Dictionary<char, int>();
Dictionary<char, int> dic2 = new Dictionary<char, int>(); int type1 = ;
int type2 = ; StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder(); foreach (var c in s)
{
if (!dic1.ContainsKey(c))
{
dic1.Add(c, type1);
sb1.Append(type1);
type1++;
}
else
{
sb1.Append(dic1[c]);
} } foreach (var c in t)
{
if (!dic2.ContainsKey(c))
{
dic2.Add(c, type2);
sb2.Append(type2);
type2++;
}
else
{
sb2.Append(dic2[c]);
}
} if (sb1.ToString() != sb2.ToString())
{
return false;
}
else
{
return true;
}
}
}
}

https://leetcode.com/problems/isomorphic-strings/#/description

leetcode205的更多相关文章

  1. [Swift]LeetCode205. 同构字符串 | Isomorphic Strings

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  2. LeetCode205----同构字符串

    给定两个字符串 s 和 t,判断它们是否是同构的. 如果 s 中的字符可以被替换得到 t ,那么这两个字符串是同构的. 所有出现的字符都必须用另一个字符替换,同时保留字符的顺序.两个字符不能映射到同一 ...

随机推荐

  1. Page.TryUpdateModel 方法

    使用来自值提供程序的值更新指定的模型实例. 使用来自值提供程序的值更新指定的模型实例. 命名空间:   System.Web.UI程序集:  System.Web(System.Web.dll 中) ...

  2. Day41 openstack基础

    参考博客: http://www.cnblogs.com/linhaifeng/p/6264636.html

  3. 003PHP文件处理——目录操作:rename scandir

    <?php //目录操作:rename scandir /** * 修改目录名字: * rename('旧名字','新名字') 改变文件夹或者文件的名称 */ //var_dump(rename ...

  4. JS获取当前时间到30天之后的日期区间

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. 用halcon提取衣服徽章

    收到一封email,有个学员求助去除衣服上纹理的干扰,然后提取衣服上徽章的边缘的方法.   我想他肯定是个很努力上进的boy,在求助以前也许已经试过各种方法,通过二值化不断的调试阈值,   寻找各种边 ...

  6. C++设计模式之职责链模式

    代码实现: // chainResbonsibility.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stri ...

  7. 判断设备(PC,安Android,iOS)

    //判断是不是PC function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = new Array("An ...

  8. Qt SD卡 文件系统挂载、文件预览

    /********************************************************************************** * Qt SD卡 文件系统挂载. ...

  9. .NET/C# 中你可以在代码中写多个 Main 函数,然后按需要随时切换

    .NET/C# 程序从 Main 函数开始执行,基本上各种书籍资料都是这么写的.不过,我们可以写多个 Main 函数,然后在项目文件中设置应该选择哪一个 Main 函数. 你可能会觉得这样没有什么用, ...

  10. TCP/IP分析

    TCP/IP四层模型 TCP/IP参考模型 ISO制定的OSI参考模型的过于庞大.复杂招致了许多批评.与此对照,由技术人员自己开发的TCP/IP协议栈获得了更为广泛的应用.如图2-1所示,是TCP/I ...