java.lang.Object
g0901_1000.s0953_verifying_an_alien_dictionary.Solution

public class Solution extends Object
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 = [&ldquo;hello&rdquo;,&ldquo;leetcode&rdquo;], order = &ldquo;hlabcdefgijkmnopqrstuvwxyz&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> As &lsquo;h&rsquo; comes before &lsquo;l&rsquo; in this language, then the sequence is sorted.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> words = [&ldquo;word&rdquo;,&ldquo;world&rdquo;,&ldquo;row&rdquo;], order = &ldquo;worldabcefghijkmnpqstuvxyz&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> As &lsquo;d&rsquo; comes after &lsquo;l&rsquo; 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 = [&ldquo;apple&rdquo;,&ldquo;app&rdquo;], order = &ldquo;abcdefghijklmnopqrstuvwxyz&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> The first three characters &ldquo;app&rdquo; match, and the second string is shorter (in size.) According to lexicographical rules &ldquo;apple&rdquo; > &ldquo;app&rdquo;, because &lsquo;l&rsquo; > &lsquo;\u2205&rsquo;, where &lsquo;\u2205&rsquo; 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 Details

    • Solution

      public Solution()
  • Method Details

    • isAlienSorted

      public boolean isAlienSorted(String[] words, String order)