【leetcode❤python】 205. Isomorphic Strings
#-*- 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的更多相关文章
- 【刷题-LeetCode】205. Isomorphic Strings
Isomorphic Strings Given two strings *s* and *t*, determine if they are isomorphic. Two strings are ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- 【LeetCode】205. Isomorphic Strings 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典保存位置 字典保存映射 日期 题目地址:http ...
- 【一天一道LeetCode】#205. Isomorphic Strings
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...
- 【LeetCode】205. Isomorphic Strings
题目: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the c ...
- 【leetcode❤python】 1. Two Sum
#-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object): def twoSum(self, nums, target): ...
- 【leetcode❤python】 58. Length of Last Word
#-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object): ...
- 【leetcode❤python】 8. String to Integer (atoi)
#-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...
- 【leetcode❤python】 165. Compare Version Numbers
#-*- coding: UTF-8 -*-class Solution(object): def compareVersion(self, version1, version2): ...
随机推荐
- c++命名规则
命名规则根据不同公司有略微不同,这里按照google c++的编程标准1.文件名-全部用小写字母和下划线或横线组成,例如my_useful_class.ccmy-useful-class.ccmyus ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON SmoothImage
zw版[转发·台湾nvp系列Delphi例程]HALCON SmoothImage procedure TForm1.Button1Click(Sender: TObject);var image0, ...
- PHP自动生成后台导航网址的最佳方法
'http://www.jbxue.com'=> '脚本学堂首页', </script>
- 一段OpenGL的简单代码
这是基于OpenGL的代码,把它放进draw中即可.渲染出来的效果还不错 #define PI 3.14159 #define N 100 void test::Draw() { glClearCol ...
- knockout之入门介绍
Knockout是一个轻量级的UI类库,通过应用MVVM模式使JavaScript的前端UI简单化.Knockout是一个以数据模型(data model)为基础的能够帮助你创建丰富文本,响应显示和编 ...
- ipseccmd命令解析
IPSec 首先需要指出的是,IPSec和TCP/IP筛选是不同的东西,大家不要混淆了.TCP/IP筛选的功能十分有限,远不如IPSec灵活和强大.下面就说说如何在命令行下控制IPSec. XP系统用 ...
- db.properties
jdbc.driverclass=oracle.jdbc.driver.OracleDriverjdbc.url=jdbc:oracle:thin:@192.168.201.192:1521:orcl ...
- html5+php实现文件的断点续传ajax异步上传
html5+php实现文件的断点续传ajax异步上传 准备知识:断点续传,既然有断,那就应该有文件分割的过程,一段一段的传.以前文件无法分割,但随着HTML5新特性的引入,类似普通字符串.数组的分割, ...
- Bind[Exclude|Include]排除字段或只允许字段验证
public ActionResult xx([Bind(Exclude = "id")] xxModel xx, HttpPostedFileBase file)//排除id验证 ...
- https笔记
TCP提供了可靠的,面向连接的字节流服务. 1)应用数据分割成TCP认为适合发送的数据块,通过MSS(最大数据包长度)来控制. 2)重传机制 3)对首部和数据进行校验 4)TCP对收到的数据进行排序, ...