题目链接:953. 验证外星语词典
如题。
from typing import List
class Solution:
def isAlienSorted(self, words: List[str], order: str) -> bool:
directory = {c: i for i, c in enumerate(order)}
def lte(w1: str, w2: str) -> bool:
return tuple(directory[c] for c in w1) <= tuple(directory[c] for c in w2)
for i in range(1, len(words)):
if not lte(words[i - 1], words[i]):
return False
return True