题目
In an alien language, surprisingly they also use english lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.
Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographicaly in this alien language.
翻译
给定一个单词组成的字符串序列,给定一个字母组成的字符串序列,判断是否该单词序列是否符合字母序列所规定的顺序。
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: fals

这道题目考察的是在外星语言中判断单词序列是否按字母表顺序排列。解决方案包括创建字母到数字的映射,替换单词中的字母并检查序列是否不降序。使用C++的auto特性简化了代码,使其类似Python的迭代方式,但要注意C++中对原始数据的修改。
最低0.47元/天 解锁文章
3813

被折叠的 条评论
为什么被折叠?



