# [LeetCode]#806. Number of Lines To Write String

`Input: widths = [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = "abcdefghijklmnopqrstuvwxyz"Output: [3,60]Explanation: You can write s as follows:abcdefghij  // 100 pixels wideklmnopqrst  // 100 pixels wideuvwxyz      // 60 pixels wideThere are a total of 3 lines, and the last line is 60 pixels wide.`
`Input: widths = [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = "bbbcccdddaaa"Output: [2,4]Explanation: You can write s as follows:bbbcccdddaa  // 98 pixels widea            // 4 pixels wideThere are a total of 2 lines, and the last line is 4 pixels wide.`
`class Solution(object):    def numberOfLines(self, widths, S):        lines = 1        ans = 0        for i in S:            width = widths[ord(i) - ord('a')]            ans += width            if ans > 100:                lines += 1                ans = width        return [lines, ans]`

--

--

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.