java.lang.Object
g0701_0800.s0720_longest_word_in_dictionary.Solution

public class Solution extends Object
720 - Longest Word in Dictionary.<p>Medium</p> <p>Given an array of strings <code>words</code> representing an English Dictionary, return <em>the longest word in</em> <code>words</code> <em>that can be built one character at a time by other words in</em> <code>words</code>.</p> <p>If there is more than one possible answer, return the longest word with the smallest lexicographical order. If there is no answer, return the empty string.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> words = [&ldquo;w&rdquo;,&ldquo;wo&rdquo;,&ldquo;wor&rdquo;,&ldquo;worl&rdquo;,&ldquo;world&rdquo;]</p> <p><strong>Output:</strong> &ldquo;world&rdquo;</p> <p><strong>Explanation:</strong> The word &ldquo;world&rdquo; can be built one character at a time by &ldquo;w&rdquo;, &ldquo;wo&rdquo;, &ldquo;wor&rdquo;, and &ldquo;worl&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> words = [&ldquo;a&rdquo;,&ldquo;banana&rdquo;,&ldquo;app&rdquo;,&ldquo;appl&rdquo;,&ldquo;ap&rdquo;,&ldquo;apply&rdquo;,&ldquo;apple&rdquo;]</p> <p><strong>Output:</strong> &ldquo;apple&rdquo;</p> <p><strong>Explanation:</strong> Both &ldquo;apply&rdquo; and &ldquo;apple&rdquo; can be built from other words in the dictionary. However, &ldquo;apple&rdquo; is lexicographically smaller than &ldquo;apply&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= words.length <= 1000</code></li> <li><code>1 <= words[i].length <= 30</code></li> <li><code>words[i]</code> consists of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details