Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 519 Bytes

806.md

File metadata and controls

30 lines (21 loc) · 519 Bytes

Number of Lines To Write String

Description

link


Solution

  • See Code

Code

O(nk)

class Solution:
    def numberOfLines(self, widths: List[int], S: str) -> List[int]:
        res = [0]
        for c in S:
            num = widths[ord(c) - 97]
            if res[-1] + num > 100:
                res.append(num)
            else:
                res[-1] += num
        return [len(res), res[-1]]