Leetcode Problem 809. Expressive Words

809. Expressive Words

Leetcode Solutions

Two Pointers Approach for Stretchy Words

  1. Define a helper function get_streaks that takes a string and returns a list of tuples, each containing a character and the length of its consecutive streak in the string.
  2. Iterate over each word in the words list.
  3. For each word, get the streaks using the get_streaks function.
  4. Compare the streaks of the current word with the streaks of s.
  5. If the number of streaks is different, the word is not stretchy. Continue to the next word.
  6. For each pair of streaks, check if the characters are the same.
  7. If the characters are different, or if the word's streak length is greater than s's streak length, or if s's streak length is less than 3 and not equal to the word's streak length, the word is not stretchy. Continue to the next word.
  8. If all streaks pass the checks, increment the count of stretchy words.
  9. Return the count of stretchy words.
UML Thumbnail

Brute Force with Character Counting

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...