def waixingren(words, order):
word = []
for i in range(len(words)):
word.append([])
max = 0
for i in range(len(words)):
if len(words[i]) > max:
max = len(words[i])
for j in range(len(words[i])):
word[i].append(order.index(words[i][j]))
for i in range(len(words)):
if len(word[i]) < max:
for j in range(max - len(word[i])):
word[i].append(0)
a = True
for i in range(len(word)):
for j in range(max):
if i != 0 and word[i][j] < word[i-1][j]:
a = False
elif i != 0 and word[i][j] > word[i-1][j]:
break
return a
def words_order(words, order):
minlenth = len(min(words))
lresult = []
for i in range(len(words)):
for j in range(len(words) - i - 1):
if len(words[j]) > len(words[j + 1]):
return "false"
else:
lresult.append(words[i][0:minlenth])
for i in range(len(lresult)):
for j in range(len(lresult[0])):
if order.index(lresult[i][j]) > order.index(lresult[i + 1][j]):
return "false"
else:
return "true"
def words_order(words: list, order: str) -> bool:
res_list=[]
for word in words:
word=word+'0'*(max([len(words[i]) for i in range(len(words))])-len(word))
word_int_list=[str(order.index(str(i))+1) if i in order else i for i in word]
res_list.append(word_int_list)
print(res_list)
for i in range(len(res_list)-1):
for j in range(len(res_list[0])):
if res_list[i][j]==res_list[i+1][j]:
continue
elif res_list[i][j]<res_list[i+1][j]:
return True
else:
return False
assert words_order(["hello","leetcode"],"hlabcdefgijkmnopqrstuvwxyz")==True
assert words_order(["word","world","row"],"worldabcefghijkmnpqstuvxyz")==False
assert words_order(["apple","app"],"abcdefghijklmnopqrstuvwxyz")==False