码迷,mamicode.com
首页 > 其他好文 > 详细

查找表_leetcode205

时间:2019-03-17 15:49:28      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:iso   false   tco   找工作   leetcode   sel   for   使用   key   


# 解题思路:字典建立隐射关系,一一对应 20190302 找工作期间


class Solution(object):
def isIsomorphic(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""


# 使用字典,pattern当key,str当value,形成配对
dic = {}

if len(s) != len(t) or len(set(s)) != len(set(t)):
return False

for i, val in enumerate(s):
if val not in dic:
dic[val] = t[i]
elif dic[val] != t[i]:
return False
return True

查找表_leetcode205

标签:iso   false   tco   找工作   leetcode   sel   for   使用   key   

原文地址:https://www.cnblogs.com/lux-ace/p/10546917.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!