MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / isIsomorphic

Method isIsomorphic

String/IsomorphicStrings.py:40–69  ·  view source on GitHub ↗

:type s: str :type t: str :rtype: bool

(self, s, t)

Source from the content-addressed store, hash-verified

38
39class Solution(object):
40 def isIsomorphic(self, s, t):
41 """
42 :type s: str
43 :type t: str
44 :rtype: bool
45 """
46
47 """
48 这里可以缩写为一个函数,但不需要复用,直接复制粘贴了。
49 """
50 s_k = 0
51 t_k = 0
52 s_d = {}
53 t_d = {}
54 new_s = ''
55 new_t = ''
56 for i in s:
57 if s_d.get(i):
58 new_s += s_d.get(i)
59 else:
60 s_d[i] = str(s_k)
61 s_k += 1
62 for i in t:
63 if t_d.get(i):
64 new_t += t_d.get(i)
65 else:
66 t_d[i] = str(t_k)
67 t_k += 1
68
69 return new_s == new_t
70
71"""
72接下来是one line 版,虽然并不是很高效,但思路不错。

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected