美文网首页leetcode
58. Length of Last Word.go

58. Length of Last Word.go

作者: AnakinSun | 来源:发表于2019-03-23 13:25 被阅读0次

简单求解

func lengthOfLastWord(s string) int {
    arr := strings.Split(strings.Trim(s, " "), " ")
    length := len(arr)
    res := 0
    for i := length - 1; i >= 0; i-- {
        if arr[i] == " " {
            continue
        } else {
            res = len(arr[i])
            break
        }
    }
    return res
}

相关文章

网友评论

    本文标题:58. Length of Last Word.go

    本文链接:https://www.haomeiwen.com/subject/coqsvqtx.html