https://leetcode.com/problems/isomorphic-strings/?envType=study-plan&id=level-1
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
d = defaultdict(str)
alpha = defaultdict(int)
for i in range(len(s)):
if s[i] not in d:
d[s[i]] = t[i]
alpha[t[i]] += 1
if alpha[t[i]] >= 2:
return False
else:
if d[s[i]] != t[i]:
return False
return True
문자열 s와t를 각각 KEY
와 VALUE
로 취급하여 해시 개념으로 문제를 풀었다.
False
(a, b -> c)False
(a -> b, c)