← 返回 apple 的题目列表Alien Dictionary
类型:online_judge
Given a dictionary of an alien language (not English letters), where the order of the letters is unknown, determine the order of the letters and return one possible order.
For example, given the following dictionary:
[
"wrt",
"wrf",
"er",
"ett",
"rftt"
]
The letter order might be: "wertf". If there's no valid order, return an empty string. You may assume that the input is valid, meaning there are no contradictions in the input dictionary.
Input
A list of words words containing the alien letters.
Output
A single string representing the possible order of letters.
Examples
Input: words = ["wrt", "wrf", "er", "ett", "rftt"]
Output: "wertf"
Input: words = ["z", "x"]
Output: "zx"
Input: words = ["z", "x", "z"]
Output: ""
Constraints
The actual data might contain 1 to 100 letters and 1 to 100 words.
Example
Input
["wrt", "wrf", "er", "ett", "rftt"]