link

 

Example 1:

Input: s = "egg", t = "add"
Output: true

Example 2:

Input: s = "foo", t = "bar"
Output: false

Example 3:

Input: s = "paper", t = "title"
Output: true
# mapping 사용
# 없으면 등록, 있을때 다르면 False

class Solution:
    def isIsomorphic(self, s: str, t: str) -> bool:
        dict = {}
        
        for i in range(len(s)):
            if len(s) != len(t) :
                return False
            
            # Dict 에 없으면 등록
            if s[i] not in dict.keys():
                if t[i] not in dict.values():
                    dict[s[i]] = t[i]
                else : 
                    return False

            # 있을때 비교
            else:  
                if dict[s[i]] != t[i]:
                    return False
                
        return True

 

'Python 문제풀이 > LeetCode' 카테고리의 다른 글

21. Merge Two Sorted Lists  (0) 2022.08.15
392. Is Subsequence  (0) 2022.08.11
724. Find Pivot Index  (0) 2022.08.09
1480. Running Sum of 1d Array  (0) 2022.08.09
617. Merge Two Binary Trees (DFS , 재귀)  (0) 2022.07.12
블로그 이미지

hjc_

୧( “̮ )୨

,