class Solution:
def isLowerOrEqual(self, word1, word2, order) -> bool:
for i in range(min(len(word1), len(word2))):
lc, rc = word1[i], word2[i]
if lc != rc:
if order.find(lc) < order.find(rc):
return True
else:
return False
if len(word1) > len(word2):
return False
return True
def isAlienSorted(self, words: List[str], order: str) -> bool:
if len(words) == 1:
return True
for i in range(len(words)-1):
if not self.isLowerOrEqual(words[i], words[i+1], order):
return False
return True