Expressive Words
specialist · 990 · lc medium +32 · verified · 46.7% accepted · 915 likes · top 31%
Description
People sometimes stretch letters in words to convey extra emotion. For instance:
- "hello" -> "heeellooo"
- "hi" -> "hiiii"
In a stretched string like "heeellooo", consecutive identical letters form groups: "h", "eee", "ll", "ooo".
You are given a string s and an array of query strings words. A query word is stretchy if it can be transformed into s by any number of extension steps, where each step selects a run of identical characters and expands it to a length of at least three.
- For example, beginning with "hello", extending the "o" run yields "hellooo" (valid, length >= 3), but "helloo" is not reachable this way because the resulting run has length 2. A further extension of "ll" -> "lllll" gives "helllllooo". If s = "helllllooo", then "hello" is stretchy via these two operations.
Return the count of stretchy query strings.
Example 1:
Example 2:
Code