# 解题思路:字典建立隐射关系,一一对应 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