地址:点击打开链接
和Word Pattern方法相似,答案都是一种
答案:
class Solution(object):
def isIsomorphic(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
return map(s.find, s) == map(t.find, t)
本文介绍了一种通过比较两个字符串中字符出现位置来判断二者是否为同构字符串的方法。使用Python实现,具体做法是利用map函数配合find方法,分别获取源字符串及目标字符串中各字符的首次出现位置,并对比两组位置是否一致。
地址:点击打开链接
和Word Pattern方法相似,答案都是一种
答案:
class Solution(object):
def isIsomorphic(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
return map(s.find, s) == map(t.find, t)

被折叠的 条评论
为什么被折叠?