Description
Given an array of strings words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully justified. Pack as many words as you can in each line. Extra spaces should be distributed as evenly as possible. The last line should be left-justified.
Examples
words = ["This", "is", "an", "example", "of", "text", "justification."], maxWidth = 16["This is an", "example of text", "justification. "]Lines are padded to exactly 16 characters.
words = ["What", "must", "be", "acknowledgment", "shall", "be"], maxWidth = 16["What must be", "acknowledgment ", "shall be "]First line fits 3 short words with extra spaces distributed evenly (3 spaces between each). Second line has one long word that takes most of the width, padded with spaces. Last line is left-justified with remaining spaces at the end.
words = ["Science", "is", "what", "we", "understand", "well", "enough"], maxWidth = 20["Science is what we", "understand well ", "enough "]First line packs 4 words with spaces distributed as evenly as possible (2 spaces between each pair). Second line fits 2 words with remaining space at end. Last line contains only one word, so it's left-justified with all remaining spaces at the end.
Constraints
- •
1 ≤ words.length ≤ 300 - •
1 ≤ words[i].length ≤ 20 - •
1 ≤ maxWidth ≤ 100