代码拉取完成,页面将自动刷新
class Solution(object):
def count_sentence_fit(self, sentence, rows, cols):
if sentence is None:
raise TypeError('sentence cannot be None')
if rows is None or cols is None:
raise TypeError('rows and cols cannot be None')
if rows < 0 or cols < 0:
raise ValueError('rows and cols cannot be negative')
if cols == 0 or not sentence:
return 0
curr_row = 0
curr_col = 0
count = 0
while curr_row < cols:
for word in sentence:
# If the current word doesn't fit on the current line,
# move to the next line
if len(word) > cols - curr_col:
curr_col = 0
curr_row += 1
# If we are beyond the number of rows, return
if curr_row >= rows:
return count
# If the current word fits on the current line,
# 'insert' it here
if len(word) <= cols - curr_col:
curr_col += len(word) + 1
# If it still doesn't fit, then the word is too long
# and we should just return the current count
else:
return count
count += 1
return count
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。