#-*- coding: UTF-8 -*-
#转换法
class Solution(object):
    def isIsomorphic(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """
        sdic={}
        slist=[]
        tdic={}
        tlist=[]
        
        if len(s)!=len(t):return False
        
        i=0;tag=0
        while i<len(s):
            if(sdic.has_key(s[i])):
                slist.append(sdic.get(s[i]))
            else:
                slist.append(tag)
                sdic.setdefault(s[i],tag)
                tag+=1
            i+=1
        
        i=0;tag=0
        while i<len(t):
            if tdic.has_key(t[i]):
                tlist.append(tdic.get(t[i]))
            else:
                tlist.append(tag)
                tdic.setdefault(t[i],tag)
                tag+=1
            i+=1
        
        return tlist==slist
    

sol=Solution()
print sol.isIsomorphic('foo', 'bar')

【leetcode❤python】 205. Isomorphic Strings的更多相关文章

  1. 【刷题-LeetCode】205. Isomorphic Strings

    Isomorphic Strings Given two strings *s* and *t*, determine if they are isomorphic. Two strings are ...

  2. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  3. 【LeetCode】205. Isomorphic Strings 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典保存位置 字典保存映射 日期 题目地址:http ...

  4. 【一天一道LeetCode】#205. Isomorphic Strings

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...

  5. 【LeetCode】205. Isomorphic Strings

    题目: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the c ...

  6. 【leetcode❤python】 1. Two Sum

    #-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object):    def twoSum(self, nums, target):  ...

  7. 【leetcode❤python】 58. Length of Last Word

    #-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object):   ...

  8. 【leetcode❤python】 8. String to Integer (atoi)

    #-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...

  9. 【leetcode❤python】 165. Compare Version Numbers

    #-*- coding: UTF-8 -*-class Solution(object):    def compareVersion(self, version1, version2):       ...

随机推荐

  1. angular 倒计时

    $scope.countdown = ; var myTime = setInterval(function() { $scope.countdown--; $scope.$digest(); // ...

  2. 项目中empty遇到的一个问题

    搜索传参时,数据能获取到,搜索结果不是根据参数得出的,在定义搜索条件时因为empty引起的一个问题,键为0的值没有获取到, 记住:!empty 已经把0排除了

  3. 使用UEFI BIOS Updater(UBU)来更新CPU微代码

    原文地址:http://www.win-raid.com/t154f16-Tool-Guide-News-quot-UEFI-BIOS-Updater-quot-UBU.html 链接: http:/ ...

  4. Ubuntu 13.10 64位 无法 安装 ia32-libs 解决办法

    安装新立德软件包管理器:打开终端,输入以下命令:sudo apt-get install synaptic 打开新立德软件包管理器,选择“设置>软件库” 选择“其他软件 > 添加” 在AP ...

  5. Android NDK 开发(三)--常见错误锦集合Log的使用【转】

    转载请注明出处:http://blog.csdn.net/allen315410/article/details/41826511  Android NDK开发经常因某些因素会出现一些意想不到的错误, ...

  6. python logging 替代print 输出内容到控制台和重定向到文件

    转自:http://blog.csdn.net/z_johnny/article/details/50740528

  7. 161208、Java enum 枚举还可以这么用

    在大部分编程语言中,枚举类型都会是一种常用而又必不可少的数据类型,Java中当然也不会例外.然而,Java中的Enum枚举类型却有着许多你意想不到的用法,下面让我们一起来看看. 先来看一段代码示例: ...

  8. JSONArray.fromObject()注入处理日期Date格式

    package jsonDateProcess; import java.sql.Date; import java.text.SimpleDateFormat; import java.util.L ...

  9. [转]Jexus的常用操作和基本配置

    转自http://www.cnblogs.com/xiaodiejinghong/archive/2013/04/05/3000404.html 3.Jexus的操作 经过两个章节关于Jexus的介绍 ...

  10. Keepalived原理及配置应用总结

    Keepalived——保持存活,在网络里的含义就是保持在线.Keepalived提供高可用和热备的功能,用来防止单点故障的发生. 1.VRRP协议基本原理介绍 Keepalived实现的基础是VRR ...