- https://leetcode.com/problems/isomorphic-strings
- https://leetcode-cn.com/problems/isomorphic-strings/
class Solution:
def isIsomorphic(self, s, t):
return len(set(zip(s, t))) == len(set(s)) == len(set(t))
同构代表两个字符串中,每个位置上字符在自身第一次出现的索引相同
class Solution:
def isIsomorphic(self, s, t):
return [s.find(i) for i in s] == [t.find(i) for i in t]
class Solution:
def isIsomorphic(self, s, t):
return [s.index(i) for i in s] == [t.index(i) for i in t]
class Solution:
def isIsomorphic(self, s, t):
return map(s.find, s) == map(t.find, t)
class Solution:
def isIsomorphic(self, s, t):
d1, d2 = {}, {}
for i, val in enumerate(s):
d1[val] = d1.get(val, []) + [i]
for i, val in enumerate(t):
d2[val] = d2.get(val, []) + [i]
return sorted(d1.values()) == sorted(d2.values())