• Why should the results of the case be like this?Distribute evenly?then,how about the latter one?

``````17 / 24 test cases passed.
Submitted: 0 minutes ago
Input:	["What","must","be","shall","be."], 12
Output:	["What must be","shall    be."]
Expected:	["What must be","shall be.   "]

Input:	["Listen","to","many,","speak","to","a","few."], 6
Output:	["Listen","to    ","many, ","speak ","to  a ","few.  "]
Expected:	["Listen","to    ","many, ","speak ","to   a","few.  "]``````

• The rules go as follow.
Put as many words, separated by a single space, as you can on one line, without exceeding the maximum number of characters. Do not put a space at the end of a line with multiple words unless it is the final line..

If only one word exists in the line, or if it is the last line of input, add spaces to the end until the length of the line is equal to the max number.

If there are multiple words in a line, but there need to be more spaces than possible with one space between each word to reach the maximum length, add a space to each division, rotating through the line from left to right, so that the left breaks have at most 1 more space than the right breaks.

``````Input:  ["What","must","be","shall","be."], 12
Output: ["What must be","shall    be."]
Expected:   ["What must be","shall be.   "]
``````

What = 4, must = 4, be = 2, requires 2 spaces: "What must be" = 12 chars

shall = 5, be. = 3, requires 1 space: "shall be." = 9, 12-9=3, so needs 3 more spaces inserted. Last line, so spaces are added to the end: `shall_be.___`

``````Input:  ["Listen","to","many,","speak","to","a","few."], 6
Output: ["Listen","to    ","many, ","speak ","to  a ","few.  "]
Expected:   ["Listen","to    ","many, ","speak ","to   a","few.  "]
``````

Listen=6, requires 0 spaces: `Listen`=6 chars

to=2, many=4, requires 1 space, 7>6, so only "to" is on the line. 6-2 = 4 spaces inserted: `to____`

many, = 5, space reaches 6. `many,_`

speak = 5, space reaches 6 `speak_`

to = 2, a = 1, few. = 4, requires 2 spaces->9, so few is not part of the line. "to a" is 4 chars, so needs 2 more. Insert through interior spaces (only one of them): `to __a`

few. = 4, needs 2 spaces to reach 6. Last line, so added to the end: `few.__`

• Thanks a lot.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.