Count the Words

Count the Words

Given a String str with multiple words, return the number of individual words.

You can assume that str will only contain upper case letters, lower case letters, numbers, and spaces. There will be no punctuation symbols.

Conditions:

  • str.length() >= 0
  • Words are separated by exactly one space
  • There will not be a space at the beginning or end of the string
countTheWords( "hello how are you" ) => 4
countTheWords( "Hello" ) => 1
countTheWords( "" ) => 0