版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/roguesir/article/details/87990662
Introduce
Given a string s consists of upper/lower-case alphabets and empty space characters ’ ', return the length of last word in the string.
If the last word does not exist, return 0.
Note: A word is defined as a character sequence consists of non-space characters only.
Example:
Input: "Hello World"
Output: 5
Solution
class Solution(object):
def lengthOfLastWord(self, s):
"""
:type s: str
:rtype: int
"""
return len(s.strip().split(" ")[-1])
https://leetcode.com/submissions/detail/202036869/
Code
GitHub:https://github.com/roguesir/LeetCode-Algorithm
- 更新时间:2019-02-27