length_of_ast_word

  • 2022-12-14
  • 浏览 (404)

length_of_ast_word.py 源码

# 最后一个单词的长度

class Solution:

    def lengthOfLastWord(self, s: str) -> int:
        if not s:
            return 0
        s = s.strip()
        res, i = 0, len(s) - 1
        while i >= 0 and s[i] != ' ':
            res, i = res + 1, i - 1
        return res

你可能感兴趣的文章

first_unique_char

implement_strstr

is_palindrome

0  赞