820. Short Encoding of Words Medium

@problem@discussion
#Array#Hash Table#String#Trie



1/**
2 * [820] Short Encoding of Words
3 *
4 * A valid encoding of an array of words is any reference string s and array of indices indices such that:
5 * 
6 * 	words.length == indices.length
7 * 	The reference string s ends with the '#' character.
8 * 	For each index indices[i], the substring of s starting from indices[i] and up to (but not including) the next '#' character is equal to words[i].
9 * 
10 * Given an array of words, return the length of the shortest reference string s possible of any valid encoding of words.
11 *  
12 * Example 1:
13 * 
14 * Input: words = ["time", "me", "bell"]
15 * Output: 10
16 * Explanation: A valid encoding would be s = "time#bell#" and indices = [0, 2, 5].
17 * words[0] = "time", the substring of s starting from indices[0] = 0 to the next '#' is underlined in "<u>time</u>#bell#"
18 * words[1] = "me", the substring of s starting from indices[1] = 2 to the next '#' is underlined in "ti<u>me</u>#bell#"
19 * words[2] = "bell", the substring of s starting from indices[2] = 5 to the next '#' is underlined in "time#<u>bell</u>#"
20 * 
21 * Example 2:
22 * 
23 * Input: words = ["t"]
24 * Output: 2
25 * Explanation: A valid encoding would be s = "t#" and indices = [0].
26 * 
27 *  
28 * Constraints:
29 * 
30 * 	1 <= words.length <= 2000
31 * 	1 <= words[i].length <= 7
32 * 	words[i] consists of only lowercase letters.
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/short-encoding-of-words/
38// discuss: https://leetcode.com/problems/short-encoding-of-words/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn minimum_length_encoding(words: Vec<String>) -> i32 {
44        0
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_820() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.