코-딩/Leetcode

[leetcode] 205. Isomorphic Strings

힞뚜루마뚜루 2023. 3. 26. 15:51
728x90

문제 : https://leetcode.com/problems/isomorphic-strings/description/

난이도 : Easy

 

풀이
class Solution:
    def isIsomorphic(self, s: str, t: str) -> bool:
        sDict = []
        tDict = []
        for idx in s:
            sDict.append(s.index(idx))
        for idx in t:
            tDict.append(t.index(idx))
        if sDict == tDict:
            return True
        return False

 

처음 나타내는 문자의 인덱스를 찾아주는 index 함수를 사용해서 각 단어들의 인덱스를 저장해준다.

그리고 그 인덱스 사전들끼리 비교해주면 된다!

728x90
댓글수0