leetcode 刷题之路 15 Length of Last Word
来源:互联网 发布:java 文本相似度 编辑:程序博客网 时间:2024/06/18 12:13
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.
For example,
Given s = "Hello World"
,
return 5
.
求一个字符串中最后一个单词的长度。这道题比较简单,考虑全面一点,注意临界情况的处理就好。
my accepted answer:
class Solution {public: int lengthOfLastWord(const char *s) { int i=strlen(s)-1; while(i>=0&&s[i]==' ') i--; if (i<0) return 0; int len=0; while(i>=0&&s[i]!=' ') { i--; len++; } return len; }};
0 0
- leetcode 刷题之路 15 Length of Last Word
- LeetCode之Length of Last Word
- leetcode 之 length of last word.
- leetcode 之 Length of Last Word
- LeetCode之Length of Last Word
- 【Leetcode】之Length of Last Word
- leetcode:字符串之Length of Last Word
- LeetCode进阶之路(Length of Last Word)
- [leetcode刷题系列]Length of Last Word
- LeetCode刷题笔录Length of Last Word
- leetcode刷题日记—— Length of Last Word
- LeetCode: Length of Last Word
- LeetCode Length of Last Word
- LeetCode : Length of Last Word
- [Leetcode] Length of Last Word
- [LeetCode] Length of Last Word
- [LeetCode]Length of Last Word
- [leetcode]Length of Last Word
- Zipper - HDU 1501 dp
- HDU 2070 Fibbonacci Number
- scanf 的匹配原则不同的编译器不一样?
- dns
- HDU 2071 Max Num
- leetcode 刷题之路 15 Length of Last Word
- 一份Java学习路线图
- NYOJ-170 网络的可靠性
- 三元运算符var a=b>c?:b:c
- python Flask JQuery使用说明
- Stanford ML - Neural Networks: Representation 神经网络表示
- 排列组合
- HDU 2072 单词数
- 生成过程中的 PCH 文件