Count Words in a Sentence

You are given a non-empty sentence as a string. The sentence contains one or more words separated by single spaces, with no leading or trailing spaces. Return…

You are given a non-empty sentence as a string. The sentence contains one or more words separated by single spaces, with no leading or trailing spaces. Return the number of words in the sentence. For example, `"the sky is blue"` contains four words, so the answer is `4`.

- `1 <= s.length <= 1000` - Words consist only of printable ASCII letters and digits. - Words are separated by exactly one space. - There are no leading or trailing spaces in the input. - Visualizer presets contain at most 40 characters and 9 words.

Example 1: input s = "the sky is blue"; output 4. The sentence contains the words "the", "sky", "is", and "blue".

Example 2: input s = "hello"; output 1. A non-empty sentence with no separator contains one word.

Example 3: input s = "Go 2 School"; output 3. Letters and digits belong to words, so the three tokens are "Go", "2", and "School".

Category: Strings. Topic: strings. Difficulty: Easy. Patterns: string-processing.