Capitalize Words

Easy~10 min

Given a string s, capitalize the first letter of each word and return the resulting string.

A "word" is defined as a contiguous sequence of non-space characters. The spacing between words should be preserved exactly as in the input.

Examples

Example 1
Input: s = "hello world"
Output: "Hello World"
Explanation: The first letter of each word is capitalized.
Example 2
Input: s = "the quick brown fox"
Output: "The Quick Brown Fox"
Example 3
Input: s = "a"
Output: "A"
Explanation: A single character word is capitalized.

Constraints

  • 0 <= s.length <= 10^5
  • s consists of English letters and spaces.
  • Words are separated by single spaces.
  • There are no leading or trailing spaces.
Code
Ctrl+EnterRun|Ctrl+⇧+EnterSubmit
Output

Run your code to see results

Use Cmd+Enter to run