代码:
from typing import List
def turePassword(wordList:List[str]) ->str:
wordList = list(set(wordList))
#排序先字符串长度,其次字典序
wordList.sort(key=lambda x :(len(x),x))
ans = ''
for i in range(len(wordList)-1,-1,-1):
flag = True
for j in range(1,len(wordList[i])):
if wordList[i][:j] not in wordList:
flag = False
break
if flag:
ans = wordList[i]
break
return ans
wordList = ['a','ab','abc','abcd','abcdef','nj','njk','n','njkl','z']
print(turePassword(wordList))