注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
VO 第三面,求大米!!!
# print("Hello")
# Given a string of text and a max columns per line, return a multi-line block of text where:
# 1. the first character of each line must be a non-whitespace character
# 2. the last character on each line must be a non-whitespace character except when there is only a single word in a line.
# 3. The last line does not have to be justified.
# The spacing between words of a line should be as evenly distributed as possible.
# The total output should have the minimal amount of lines necessary to figth = [], 0
res = []
for w in s:
if cur_length + 1 + len(w) > k:
res.append(format(row,k))
row, cur_length = [], 0
cur_length += (1 + len(w))
row.append(w)
res.append(format(row,k))
return res
test1 = solution("An apple a day keeps the doctor away.", 12)
print(test1) |