【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): ...
随机推荐
- ThinkPHP讲解(六)——添加数据
添加数据到数据库有三种方式 第一种:使用数组添加 $model=D("Info"); //实例化对象 //添加数据的第一种方式:使用数组添加 //要添加的数组,必须是关联数组,ke ...
- Mysql 查询Hash分区
select * from information_schema.partitions where table_schema=database() and table_name='table_name ...
- PHP 文件上传的综合实例
1.upload.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <htm ...
- Job类
当我们在写MapReduce程序的时候,通常,在main函数里,我们会像下面这样做.建立一个Job对象,设置它的JobName,然后配置输入输出路径,设置我们的Mapper类和Reducer类,设置I ...
- SQLServer出现 '其他会话正在使用事务的上下文' 的问题原因,什么是环回链接服务器?(转载)
本人经过百度查找并且自己进行测试得到问题原因: MSDN上看了一下说是sql server 不支持在分布式事务处理中存在指向本地的链接服务器(环回链接服务器) 通过上面简单说明大家有可能没完全理解环回 ...
- kernel32.dll出错解决方案
kernel32.dll 一.什么是kernel32内核文件 kernel32.dll是Windows 9x/Me中非常重要的32位动态链接库文件,属于内核级文件.它控制着系统的内存管理.数据的输入输 ...
- Eclipse帮助文档配置
Force Eclipse To Use Local Javadocs For Context-Sensitive Help 转自:http://www.gnostice.com/nl_article ...
- Java中IO流中所涉及到的各类方法介绍
IO流之字节流 (1)IO用于在设备间进行数据传输的操作 (2)分类: A:流向 输入流 读取数据 输出流 写出数据 B:数据类型 字节流 字节输入流 字节输出流 字符流 字符输入流 字符输出流 注意 ...
- 【jQuery UI 1.8 The User Interface Library for jQuery】.学习笔记.3.创建控件
像jQuery提供 fn.extend() 方法从而可以简单地创建插件一样,jQuery UI也提供了机制使得创造插件变得简单,也确保了公共API功能在新的插件中被保留. 1.首先,创建一个名为 j ...
- eclipse内置tomcat启动方法
tomcat:run -Dmaven.tomcat.port=