Return the number of words in the text s. Words are separated by one or more spaces; there may also be spaces at the beginning or end. A string with no words gives 0.
Examples
Input: s = "the cat sat"
Output: 3
Input: s = " spaced out "
Output: 2
Constraints
0 <= len(s) <= 5000smay contain letters, digits, spaces and punctuation
Goals
- Split on whitespace
- Count the resulting words
- Handle leading, trailing and repeated spaces