← 返回 meta 的题目列表Verifying an Alien Dictionary
类型:online_judge
Problem: Verifying an Alien Dictionary
You are given an array of strings words, where each word contains only lowercase English letters. You are also given a string order, representing the alphabetical order of an alien language.
Return whether words are sorted lexicographically according to this alien alphabet.
Input Format
The first line contains an integer n, the number of words.
The next n lines each contain one string, representing words[i].
The last line contains the string order, whose length is 26 and contains every lowercase English letter exactly once.
Output Format
Print true if words are sorted according to the alien dictionary order.
Otherwise, print false.
Constraints
1 <= n <= 100
1 <= words[i].length <= 20
order.length == 26
words[i] and order contain only lowercase English letters.
Every letter appears exactly once in order.
Example 1
Input:
2
hello
leetcode
hlabcdefgijkmnopqrstuvwxyz
Output:
true
Example 2
Input:
2
word
world
worldabcefghijkmnpqstuvxyz
Output:
false
Example 3
Input:
3
apple
app
abcdefghijklmnopqrstuvwxyz
Output:
false
Example
Input
2
hello
leetcode
hlabcdefgijkmnopqrstuvwxyz
Output
true