Skip to content

Latest commit

 

History

History
executable file
·
8 lines (4 loc) · 638 Bytes

File metadata and controls

executable file
·
8 lines (4 loc) · 638 Bytes

68. Text Justification

I think this is a really easy question. We can use a greedy policy to add words in a line. first we add one word. then we add a space and a word again. If the lenghth > maxWidth then stops. then we have append k words. k-1 space. then we have (maxWidth - k words' length) space to allocate. we can use a loop and each time the k-1 space 1th 2th 3th ... k-1 th space + 1; unitl we use all space to simulate the divide.

If there is only one word in the string we need to add more space in the end. I think this is really simple question.

append(number,entity) append number*entity in the string or vectors