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

• `result` is the total number of lines.
• `result` is the width of the last line in pixels.
`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.`
1. Check s in widths value
2. Summary it.
3. If summary >100, and lines+=1
4. the last is last summary (Summary2 is below example).
`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]`

--

--