720. Longest Word in Dictionary Medium
1/**
2 * [720] Longest Word in Dictionary
3 *
4 * Given an array of strings words representing an English Dictionary, return the longest word in words that can be built one character at a time by other words in words.
5 * 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.
6 * Note that the word should be built from left to right with each additional character being added to the end of a previous word.
7 *
8 * Example 1:
9 *
10 * Input: words = ["w","wo","wor","worl","world"]
11 * Output: "world"
12 * Explanation: The word "world" can be built one character at a time by "w", "wo", "wor", and "worl".
13 *
14 * Example 2:
15 *
16 * Input: words = ["a","banana","app","appl","ap","apply","apple"]
17 * Output: "apple"
18 * Explanation: Both "apply" and "apple" can be built from other words in the dictionary. However, "apple" is lexicographically smaller than "apply".
19 *
20 *
21 * Constraints:
22 *
23 * 1 <= words.length <= 1000
24 * 1 <= words[i].length <= 30
25 * words[i] consists of lowercase English letters.
26 *
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/longest-word-in-dictionary/
31// discuss: https://leetcode.com/problems/longest-word-in-dictionary/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36 pub fn longest_word(words: Vec<String>) -> String {
37 String::new()
38 }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_720() {
49 }
50}
51
Back
© 2025 bowen.ge All Rights Reserved.