Easy
Quiz
#434 Number of Segments in a String
APPROACH
Given a string s, return the number of segments it contains. A segment is a maximal run of non-whitespace characters. Any amount of surrounding or separating whitespace does not count as part of a segment.
Example 1:
Input: s = "Hello, my name is John"
Output: 5
Explanation: The five segments are ["Hello,", "my", "name", "is", "John"]
Example 2:
Input: s = "Hello"
Output: 1
1 of 4
1:00
What is the optimal approach for this problem?