Guest User

Untitled

a guest
Mar 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. class Solution(object):
  2. def fullJustify(self, words, maxWidth):
  3.  
  4. res, curr, num_of_letters = [], [], 0
  5.  
  6. for w in words:
  7. if num_of_letters + len(w) + len(curr) > maxWidth:
  8. num_of_spaces = maxWidth - num_of_letters
  9. words_amout = len(curr) - 1 or 1
  10. for i in range(num_of_spaces):
  11. curr[i % words_amout] += ' '
  12.  
  13. res.append(''.join(curr))
  14. curr, num_of_letters = [], 0
  15. curr += [w]
  16. num_of_letters += len(w)
  17. return res + [' '.join(curr).ljust(maxWidth)]
Add Comment
Please, Sign In to add comment