There is a new alien language which uses the latin alphabet. However, the order among letters are unknown to you. You receive a list of non-empty words from the dictionary, where words are sorted lexicographically by the rules of this new language. Derive the order of letters in this language.
Contact me on wechat to get Amazon、Google requent Interview questions . (wechat id : jiuzhang0607)
Example 1:
Input:["wrt","wrf","er","ett","rftt"]
Output:"wertf"
Explanation:
from "wrt"and"wrf" ,we can get 't'<'f'
from "wrt"and"er" ,we can get 'w'<'e'
from "er"and"ett" ,we can get 'r'<'t'
from "ett"and"rftt" ,we can get 'e'<'r'
So return "wertf"
Example 2:
Input:["z","x"]
Output:"zx"
Explanation:
from "z" and "x",we can get 'z' < 'x'
So return "zx"
題目給定一個 字串陣列 words,
其中假定這些 words 中的字串是造著某一種字典序來判斷
也就是對兩個 word[i], word[j] 如果 i < j
必須是以下的可能
要求要透過給定的 words 來找出這些字元的字典序排列
假設存在字典序的話,以最小字典序來回傳
然後把這些字元順序組成一個字串回傳
假設沒有則回傳 “”