luoheng
10/7/2019 - 7:37 AM

numberOfLines

func numberOfLines(widths []int, S string) []int {
    if len(S) == 0 {
        return []int{0, 0}
    }
    newLine, curWidth := 1, 100
    for _, a := range S {
        if widths[a-'a'] > curWidth {
            newLine++
            curWidth = 100 - widths[a-'a']
        } else {
            curWidth -= widths[a-'a']
        }
    }
    return []int{newLine, 100 - curWidth}
    
}