class Solution(object):
def translateWord(self, originWord):
alphabets = [str(x) for x in range(128)]
dict = {}
translatedWord = ""
# 1. originWor의 문자를 순회
for char in originWord:
# 2. char갸 dict에 있는 지 체크
if char not in dict.keys():
dict[char] = alphabets.pop(0)+","
# 3. translatedWord 업데이트
translatedWord += dict[char]
# 4. translatedWord 리턴
return translatedWord
def isIsomorphic(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
# s 나라의 단어와 t 나라의 단어를 X나라의 단어로 각 바꿔서 같은 단어인지 확인해보자
translated_s = self.translateWord(s)
translated_t = self.translateWord(t)
if translated_s == translated_t:
return True
return False
class Solution(object):
def isIsomorphic(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
# Init Dictionary
d = {}
used = []
# Loop range(0, s.length)
for i in range(0, len(s)):
# s[i] in d?
if(s[i] in d):
# Test s[i] in dictionary matched t[i]
if( d[s[i]] == t[i] ):
continue
else:
return False
pass
else:
if t[i] in used:
return False
# Update Dictionary
d[s[i]] = t[i]
used.append(t[i])
pass
# s and t is Isomorphic
return True