【LeetCode】Length of Last Word 解题报告
2017-08-24 15:46
411 查看
【LeetCode】Length of Last Word 解题报告
标签(空格分隔): LeetCode题目地址:https://leetcode.com/problems/length-of-last-word/description/
题目描述:
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.
Examle:
input:"Hello World" "Hello World " "Hello W orld" "Hello Wo rld"
output:
5 5 4 3
Ways
使用库函数,方法比较简单,一行代码。class Solution(object): def lengthOfLastWord(self, s): """ :type s: str :rtype: int """ return len(s.strip().split(' ')[-1])
Date
2017 年 8 月 24 日相关文章推荐
- [Leetcode] Length of Last Word 解题报告
- [Leetcode] Length of Last Word 解题报告
- [leetcode] 58. Length of Last Word 解题报告
- [Leetcode] 58. Length of Last Word 解题报告
- Leetcode #58. Length of Last Word 末尾词长 解题报告
- leetcode-Length of Last Word(2014.3.31)
- *(leetcode_string) Length of Last Word
- [LeetCode]Word Break,解题报告
- LeetCode : Length of Last Word
- LeetCode — Word Break II 解题报告
- [Leetcode] Length of Last Word (Java)
- Leetcode Problem.58—Length of Last Word
- [Leetcode] Length of last word 最后一个单词的长度
- [Leetcode] 411. Minimum Unique Word Abbreviation 解题报告
- LeetCode(59)Length of Last Word
- [leetcode]Length of Last Word (求最后一个单词的长度 C语言实现)
- LeetCode 之 Length of Last Word — C 实现
- leetcode_c++:Length of Last Word(058)
- Leetcode 之Length of Last Word(38)
- Leetcode-Length of Last Word