P21889 [GeeksforGeeks] Count the characters in each word in a given sentence3451
普及-
题目描述

Given a string containing multiple words, count the characters in each word and display them.
Example 1:
Input:
S = "the quick brown fox"
Output: 3 5 5 3
Explanation: "the" has 3 characters
"quick" has 5 characters
"brown" has 5 characters
"fox" has 3 characters
​Example 2:
Input:
S = "geeks for geeks"
Output: 5 3 5
Explanation: "geeks" has 5 characters
"for" has 3 characters
"geeks" has 5 characters
Your Task:
You don't need to read input or print anything. Your task is to complete the function countChars() which takes the string S as inputs are returns an array containing the number of characters in each word of the string in the order as they appear in the input string S.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(|S|) (for output).
Constraints:
1 <= |S| <= 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
S = "the quick brown fox"
样例输出
3 5 5 3