Skip to content

Commit f8edc55

Browse files
authored
Update readme.md
1 parent f85dfb0 commit f8edc55

File tree

1 file changed

+32
-10
lines changed
  • src/main/kotlin/g0001_0100/s0068_text_justification

1 file changed

+32
-10
lines changed
Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
1-
67\. Add Binary
1+
68\. Text Justification
22

3-
Easy
3+
Hard
44

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.
618

719
**Example 1:**
820

9-
**Input:** a = "11", b = "1"
21+
**Input:** words = ["This", "is", "an", "example", "of", "text", "justification."], maxWidth = 16
1022

11-
**Output:** "100"
23+
**Output:** [ "This is an", "example of text", "justification. " ]
1224

1325
**Example 2:**
1426

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
1636

17-
**Output:** "10101"
37+
**Output:** [ "Science is what we", "understand well", "enough to explain to", "a computer. Art is", "everything else we", "do " ]
1838

1939
**Constraints:**
2040

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

Comments
 (0)