You are given a string text consisting of words separated by spaces.
Rearrange the spaces such that they are distributed equally between every pair of adjacent words, maximizing the number of spaces between them. Any remaining spaces that cannot be evenly distributed must be appended to the end of the string.
Return the resulting string after rearranging the spaces.
Note: If
textcontains onlyword, no spaces can be placed between words, so all spaces must be appended to the end of the string.
Constraints:
text.length
text consists of lowercase English letters and ' '.
text contains at least
You are given a string text consisting of words separated by spaces.
Rearrange the spaces such that they are distributed equally between every pair of adjacent words, maximizing the number of spaces between them. Any remaining spaces that cannot be evenly distributed must be appended to the end of the string.
Return the resulting string after rearranging the spaces.
Note: If
textcontains onlyword, no spaces can be placed between words, so all spaces must be appended to the end of the string.
Constraints:
text.length
text consists of lowercase English letters and ' '.
text contains at least