mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
[pre-commit.ci] pre-commit autoupdate (#11473)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.10 → v0.5.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.10...v0.5.0) - [github.com/pre-commit/mirrors-mypy: v1.10.0 → v1.10.1](https://github.com/pre-commit/mirrors-mypy/compare/v1.10.0...v1.10.1) * Fix ruff issues * Fix ruff issues --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
![66853113+pre-commit-ci[bot]@users.noreply.github.com](/assets/img/avatar_default.png)
committed by
GitHub

parent
6882a8b808
commit
716bdeb68b
@ -67,19 +67,19 @@ def text_justification(word: str, max_width: int) -> list:
|
||||
answer = []
|
||||
line: list[str] = []
|
||||
width = 0
|
||||
for word in words:
|
||||
if width + len(word) + len(line) <= max_width:
|
||||
for inner_word in words:
|
||||
if width + len(inner_word) + len(line) <= max_width:
|
||||
# keep adding words until we can fill out max_width
|
||||
# width = sum of length of all words (without overall_spaces_count)
|
||||
# len(word) = length of current word
|
||||
# len(inner_word) = length of current inner_word
|
||||
# len(line) = number of overall_spaces_count to insert between words
|
||||
line.append(word)
|
||||
width += len(word)
|
||||
line.append(inner_word)
|
||||
width += len(inner_word)
|
||||
else:
|
||||
# justify the line and add it to result
|
||||
answer.append(justify(line, width, max_width))
|
||||
# reset new line and new width
|
||||
line, width = [word], len(word)
|
||||
line, width = [inner_word], len(inner_word)
|
||||
remaining_spaces = max_width - width - len(line)
|
||||
answer.append(" ".join(line) + (remaining_spaces + 1) * " ")
|
||||
return answer
|
||||
|
Reference in New Issue
Block a user