809. Expressive Words Medium

@problem@discussion
#Array#Two Pointers#String



1/**
2 * [809] Expressive Words
3 *
4 * Sometimes people repeat letters to represent extra feeling. For example:
5 * 
6 * 	"hello" -> "heeellooo"
7 * 	"hi" -> "hiiii"
8 * 
9 * In these strings like "heeellooo", we have groups of adjacent letters that are all the same: "h", "eee", "ll", "ooo".
10 * You are given a string s and an array of query strings words. A query word is stretchy if it can be made to be equal to s by any number of applications of the following extension operation: choose a group consisting of characters c, and add some number of characters c to the group so that the size of the group is three or more.
11 * 
12 * 	For example, starting with "hello", we could do an extension on the group "o" to get "hellooo", but we cannot get "helloo" since the group "oo" has a size less than three. Also, we could do another extension like "ll" -> "lllll" to get "helllllooo". If s = "helllllooo", then the query word "hello" would be stretchy because of these two extension operations: query = "hello" -> "hellooo" -> "helllllooo" = s.
13 * 
14 * Return the number of query strings that are stretchy.
15 *  
16 * Example 1:
17 * 
18 * Input: s = "heeellooo", words = ["hello", "hi", "helo"]
19 * Output: 1
20 * Explanation: 
21 * We can extend "e" and "o" in the word "hello" to get "heeellooo".
22 * We can't extend "helo" to get "heeellooo" because the group "ll" is not size 3 or more.
23 * 
24 * Example 2:
25 * 
26 * Input: s = "zzzzzyyyyy", words = ["zzyy","zy","zyy"]
27 * Output: 3
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	1 <= s.length, words.length <= 100
33 * 	1 <= words[i].length <= 100
34 * 	s and words[i] consist of lowercase letters.
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/expressive-words/
40// discuss: https://leetcode.com/problems/expressive-words/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn expressive_words(s: String, words: Vec<String>) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_809() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.