Collapse Extra Spaces In Place
Problem statement
Remove leading and trailing ASCII spaces from text and replace every nonempty internal run of spaces with one space. Return the normalized string.
Function
collapseSpaces(text: String) → StringExamples
Example 1
text = "hello world there"return = "hello world there"Each internal run collapses to one space.
Constraints
0 <= text.length <= 10^5.