Class Solution
java.lang.Object
g0901_1000.s0953_verifying_an_alien_dictionary.Solution
953 - Verifying an Alien Dictionary.<p>Easy</p>
<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><strong>Example 1:</strong></p>
<p><strong>Input:</strong> words = [“hello”,“leetcode”], order = “hlabcdefgijkmnopqrstuvwxyz”</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> As ‘h’ comes before ‘l’ in this language, then the sequence is sorted.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> words = [“word”,“world”,“row”], order = “worldabcefghijkmnpqstuvxyz”</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> As ‘d’ comes after ‘l’ in this language, then words[0] > words[1], hence the sequence is unsorted.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> words = [“apple”,“app”], order = “abcdefghijklmnopqrstuvwxyz”</p>
<p><strong>Output:</strong> false</p>
<p><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’ > ‘\u2205’, where ‘\u2205’ is defined as the blank character which is less than any other character (<a href="https://en.wikipedia.org/wiki/Lexicographical_order" target="_top">More info</a>).</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>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
isAlienSorted
-