HTMLify

LeetCode - Number of Lines To Write String - Go
Views: 35 | Author: abh
func numberOfLines(widths []int, s string) []int {
    var line, lw int
    line = 1
    for _, c := range s {
        w := widths[c-97]
        if lw + w > 100 {
            line++
            lw = 0
        }
        lw += w
    }
    return []int{line, lw}
}

Comments