bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 68. Text Justification

68. Text Justification

Leetcode Solutions

Key approach of the solution.

  1. Initialize an empty list ans to store the justified text, and an index i to keep track of the current word.
  2. While i is less than the length of words, repeat the following steps: a. Call getWords(i) to determine the words that fit on the current line and store them in currentLine. b. Increment i by the length of currentLine. c. Call createLine(currentLine, i) to format the line according to the justification rules and add the result to ans.
  3. Return ans as the final justified text.
UML Thumbnail

Alternative approach using line-by-line construction

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...