> For the complete documentation index, see [llms.txt](https://emmaguo100.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emmaguo100.gitbook.io/leetcode/04-27-2022-68.md).

# 04//27/2022 68

```
1.Calculate the maximum number of word each line could pack-> next
    2.Calculate the length of the space of each line = maxWidth - count
    3.Distribute the space as evenly as possible, if we could not distribute evenly, we add the reminder space from left to right
       i.At the last line or there is only word in the line - we should deal as special case
       ii.Not at the last line - be careful of the case when number of the space is not even
    Specific process:
    	1. How do we know what is the maximum number of word we could pack each line?
    	We compare maxWidth with total of( n-words length + (n-1)Space)
    	e.x ["This", "is", "an", "example", "of", "text", "justification."]  maxWidth = 16
    	The maximum words we could insert are "-->This is an" 4+1+2+1+2=10,could we add one more word "example", obviously impossible
   		
   	2.To find the number of space in each line, we could just have maxWidth minus the length of all words in this line
   	In the above example would be 16-10 = 6 --> we will have 6 space at this line
   		
   	3. When we have the numbers of space, we need to insert the space b.w the word. How to do so?
   	    a. If this line is the last line, it should be left justified and no extra space is inserted between words.
  	    b. If this line is not the last line, we have another two cases to consider:
  		i.space could be evenly contributed
  	        ii. space could not be evenly contrinuted -> we insert the remain space from left to right
```
