[LeetCode] 953. Verifying an Alien Dictionary

김민우·2023년 2월 2일
0

알고리즘

목록 보기
130/189

- Problem

953. Verifying an Alien Dictionary


- 내 풀이

class Solution:
    def isAlienSorted(self, words: List[str], order: str) -> bool:
        N = len(words)
        dic = {c: i for i, c in enumerate(order)}
        alien_words = []

        for word in words:
            new_word = []
            for c in word:
                new_word.append(dic[c])
            alien_words.append(new_word)
        
        for i in range(1, N):
            word1, word2 = alien_words[i-1], alien_words[i]
            if word1 > word2:
                return False

        return True

- 결과

profile
Pay it forward.

0개의 댓글