748. Shortest Completing Word Easy
1/**
2 * [748] Shortest Completing Word
3 *
4 * Given a string licensePlate and an array of strings words, find the shortest completing word in words.
5 * A completing word is a word that contains all the letters in licensePlate. Ignore numbers and spaces in licensePlate, and treat letters as case insensitive. If a letter appears more than once in licensePlate, then it must appear in the word the same number of times or more.
6 * For example, if licensePlate = "aBc 12c", then it contains letters 'a', 'b' (ignoring case), and 'c' twice. Possible completing words are "abccdef", "caaacab", and "cbca".
7 * Return the shortest completing word in words. It is guaranteed an answer exists. If there are multiple shortest completing words, return the first one that occurs in words.
8 *
9 * Example 1:
10 *
11 * Input: licensePlate = "1s3 PSt", words = ["step","steps","stripe","stepple"]
12 * Output: "steps"
13 * Explanation: licensePlate contains letters 's', 'p', 's' (ignoring case), and 't'.
14 * "step" contains 't' and 'p', but only contains 1 's'.
15 * "steps" contains 't', 'p', and both 's' characters.
16 * "stripe" is missing an 's'.
17 * "stepple" is missing an 's'.
18 * Since "steps" is the only word containing all the letters, that is the answer.
19 *
20 * Example 2:
21 *
22 * Input: licensePlate = "1s3 456", words = ["looks","pest","stew","show"]
23 * Output: "pest"
24 * Explanation: licensePlate only contains the letter 's'. All the words contain 's', but among these "pest", "stew", and "show" are shortest. The answer is "pest" because it is the word that appears earliest of the 3.
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= licensePlate.length <= 7
30 * licensePlate contains digits, letters (uppercase or lowercase), or space ' '.
31 * 1 <= words.length <= 1000
32 * 1 <= words[i].length <= 15
33 * words[i] consists of lower case English letters.
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/shortest-completing-word/
39// discuss: https://leetcode.com/problems/shortest-completing-word/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn shortest_completing_word(license_plate: String, words: Vec<String>) -> String {
45 String::new()
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_748() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.