Description
Given a sequence of words in an alien language sorted lexicographically by their rules, return true if words are sorted in that alien dictionary order.
Examples
Input:
words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"Output:
trueExplanation:
h < l in alien order.
Input:
words = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz"Output:
falseExplanation:
In the alien alphabet, 'd' comes after 'l', so "word" > "world". The words are not in sorted order.
Input:
words = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz"Output:
falseExplanation:
Although 'app' is a prefix of 'apple', in lexicographical order the shorter word should come first. Since 'apple' appears before 'app' in the input, the words are not properly sorted.
Constraints
- •
1 ≤ words.length ≤ 100