|
1 | | -67\. Add Binary |
| 1 | +68\. Text Justification |
2 | 2 |
|
3 | | -Easy |
| 3 | +Hard |
4 | 4 |
|
5 | | -Given two binary strings `a` and `b`, return _their sum as a binary string_. |
| 5 | +Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified. |
| 6 | + |
| 7 | +You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that each line has exactly `maxWidth` characters. |
| 8 | + |
| 9 | +Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line does not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right. |
| 10 | + |
| 11 | +For the last line of text, it should be left-justified and no extra space is inserted between words. |
| 12 | + |
| 13 | +**Note:** |
| 14 | + |
| 15 | +* A word is defined as a character sequence consisting of non-space characters only. |
| 16 | +* Each word's length is guaranteed to be greater than 0 and not exceed maxWidth. |
| 17 | +* The input array `words` contains at least one word. |
6 | 18 |
|
7 | 19 | **Example 1:** |
8 | 20 |
|
9 | | -**Input:** a = "11", b = "1" |
| 21 | +**Input:** words = ["This", "is", "an", "example", "of", "text", "justification."], maxWidth = 16 |
10 | 22 |
|
11 | | -**Output:** "100" |
| 23 | +**Output:** [ "This is an", "example of text", "justification. " ] |
12 | 24 |
|
13 | 25 | **Example 2:** |
14 | 26 |
|
15 | | -**Input:** a = "1010", b = "1011" |
| 27 | +**Input:** words = ["What","must","be","acknowledgment","shall","be"], maxWidth = 16 |
| 28 | + |
| 29 | +**Output:** [ "What must be", "acknowledgment ", "shall be " ] |
| 30 | + |
| 31 | +**Explanation:** Note that the last line is "shall be " instead of "shall be", because the last line must be left-justified instead of fully-justified. Note that the second line is also left-justified becase it contains only one word. |
| 32 | + |
| 33 | +**Example 3:** |
| 34 | + |
| 35 | +**Input:** words = ["Science","is","what","we","understand","well","enough","to","explain","to","a","computer.","Art","is","everything","else","we","do"], maxWidth = 20 |
16 | 36 |
|
17 | | -**Output:** "10101" |
| 37 | +**Output:** [ "Science is what we", "understand well", "enough to explain to", "a computer. Art is", "everything else we", "do " ] |
18 | 38 |
|
19 | 39 | **Constraints:** |
20 | 40 |
|
21 | | -* <code>1 <= a.length, b.length <= 10<sup>4</sup></code> |
22 | | -* `a` and `b` consist only of `'0'` or `'1'` characters. |
23 | | -* Each string does not contain leading zeros except for the zero itself. |
| 41 | +* `1 <= words.length <= 300` |
| 42 | +* `1 <= words[i].length <= 20` |
| 43 | +* `words[i]` consists of only English letters and symbols. |
| 44 | +* `1 <= maxWidth <= 100` |
| 45 | +* `words[i].length <= maxWidth` |
0 commit comments