mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
39 lines
2.1 KiB
HTML
39 lines
2.1 KiB
HTML
|
<p>In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different <code>order</code>. The <code>order</code> of the alphabet is some permutation of lowercase letters.</p>
|
||
|
|
||
|
<p>Given a sequence of <code>words</code> written in the alien language, and the <code>order</code> of the alphabet, return <code>true</code> if and only if the given <code>words</code> are sorted lexicographically in this alien language.</p>
|
||
|
|
||
|
<p> </p>
|
||
|
<p><strong>Example 1:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
<strong>Input:</strong> words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"
|
||
|
<strong>Output:</strong> true
|
||
|
<strong>Explanation: </strong>As 'h' comes before 'l' in this language, then the sequence is sorted.
|
||
|
</pre>
|
||
|
|
||
|
<p><strong>Example 2:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
<strong>Input:</strong> words = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz"
|
||
|
<strong>Output:</strong> false
|
||
|
<strong>Explanation: </strong>As 'd' comes after 'l' in this language, then words[0] > words[1], hence the sequence is unsorted.
|
||
|
</pre>
|
||
|
|
||
|
<p><strong>Example 3:</strong></p>
|
||
|
|
||
|
<pre>
|
||
|
<strong>Input:</strong> words = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz"
|
||
|
<strong>Output:</strong> false
|
||
|
<strong>Explanation: </strong>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 (<a href="https://en.wikipedia.org/wiki/Lexicographical_order" target="_blank">More info</a>).
|
||
|
</pre>
|
||
|
|
||
|
<p> </p>
|
||
|
<p><strong>Constraints:</strong></p>
|
||
|
|
||
|
<ul>
|
||
|
<li><code>1 <= words.length <= 100</code></li>
|
||
|
<li><code>1 <= words[i].length <= 20</code></li>
|
||
|
<li><code>order.length == 26</code></li>
|
||
|
<li>All characters in <code>words[i]</code> and <code>order</code> are English lowercase letters.</li>
|
||
|
</ul>
|