3ms Golang solution


  • 0
    M
    func lengthOfLastWord(s string) int {
        flip := true
        i, j := 0, 0
        for k, l := 0, len(s); k < l; k++ {
            if string(s[k]) != " " {
                if flip {
                    i = k
                    flip = false
                }
                j = k + 1
            } else {
                flip = true
            }
        }
        return j - i
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.