Text Justification
Hard · Strings
Write a function justify that formats words into lines that are exactly maxWidth characters long.
- Put as many words as fit on each line (words need at least one space between them).
- Every line except the last is fully justified: spread the spaces between words as evenly as possible. If they do not divide evenly, the gaps on the left get one extra space.
- A line with a single word is left-aligned and padded with spaces on the right.
- The last line is left-aligned with single spaces between words, padded with spaces on the right.
Every word is at most maxWidth long. Return the array of lines.
Next: Evaluate an Expression