Remove Extra Spaces
Practice Remove Extra Spaces for free on NudgeCode: Easy, Two Pointers pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Given a string s of letters and spaces, return a new string with all leading and trailing spaces removed and every run of spaces in the middle reduced to one space. Do it with two pointers over a character array rather than split.
Example
s = " abc de " -> "abc de"
Constraints
- 0 <= s.length <= 10^4
scontains English letters and spaces
This is the first step of LC 151 (Reverse Words in a String).