- 205.同构字符串
- 21.合并两个有序链表
- 122.买卖股票的最佳时机Ⅱ
- 234.回文链表
205.同构字符串
class Solution(object):
def isIsomorphic(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
mapping = dict()
for i, char in enumerate(s):
if char in mapping:
if mapping[char]!=t[i]:
return False
else:
if t[i] in mapping.values(): # dictionary.values()返回字典中的所有值,':'后面的
return False
mapping[char] = t[i]
return True