#953

Verifying an Alien Dictionary

pupil · 435 · lc easy +25 · verified · 55.9% accepted · 5,073 likes · top 49%

Description

An alien language uses the same lowercase letters as English but sorted according to a custom order string. Given a list of words written in this language, determine whether the list is sorted according to the alien alphabet. Return true if it is, false otherwise.

Example 1:

Input: words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"
Output: true
Explanation: As 'h' comes before 'l' in this language, then the sequence is sorted.

Example 2:

Input: words = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz"
Output: false
Explanation: As 'd' comes after 'l' in this language, then words[0] > words[1], hence the sequence is unsorted.

Example 3:

Input: words = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz"
Output: false
Explanation: The first three characters "app" match, and the second string is shorter (in size.) According to lexicographical rules "apple" > "app", because 'l' > '∅', where '∅' is defined as the blank character which is less than any other character (More info).

Code

1
2
3