题目如下:
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 words from the dictionary, where words are sorted lexicographically by the rules of this new language. Derive the order of letters in this language.
For example,
Given the following words in dictionary,
[
"wrt",
"wrf",
"er",
"ett",
"rftt"
]
The correct order is: "wertf".
Note:
You may assume all letters are in lowercase.
If the order is invalid, return an empty string.
There may be multiple valid order of letters, return any one of them is fine.
分析:
先看上面的例子。
先看所有单词的第0个字符,可以知道先后顺序是w->e-r。
再看第1个字符,先后顺序是r->t,
再看第3个字符,先后顺序是t->f
当有有了若干部分的依赖关系之后,想得到完成的排序,那么可以