leetcode每日一题-目录
题目链接 806. 写字符串需要的行数
class Solution:
def numberOfLines(self, widths: List[int], s: str) -> List[int]:
lines, width = 1, 0
for c in s:
need = widths[ord(c) - ord('a')]
width += need
if width > 100:
lines += 1
width = need
return [lines, width]