[leetcode 58] Length of Last Word
来源:互联网 发布:知乎越来越差 编辑:程序博客网 时间:2024/04/25 15:43
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
.
class Solution {public: int lengthOfLastWord(const char *s) { const int n = strlen(s); int res = 0; int ind = n - 1; while (ind >= 0 && *(s+ind) == ' ') { ind--; } while (ind >= 0 && *(s+ind) != ' ') { ind--; res++; } return res; }};
0 0
- [leetcode 58] Length of Last Word
- leetcode-58 Length of Last Word
- Leetcode NO.58 Length of Last Word
- LeetCode #58 length of Last Word
- [LeetCode 58]Length of Last Word
- leetcode || 58、Length of Last Word
- LeetCode 58 Length of Last Word
- [Leetcode 58, easy] Length of Last Word
- Length of Last Word (leetCode 58)
- leetcode[58]:Length of Last Word
- 【leetcode c++】58 Length of Last Word
- leetcode 58:Length of Last Word
- LeetCode---(58)Length of Last Word
- leetcode-58-Length of Last Word
- Leetcode# 58 Length of Last Word
- [leetcode-58]Length of Last Word(c)
- leetcode 58: Length of Last Word
- leetCode #58 Length of Last Word
- Android有用代码片段(四)
- SSL/TLS的原理以及互联网究竟是如何工作的(5)—DNS和他的兄弟
- nginx中获取当前时间的函数
- oracle ASM 如何添加新磁盘到磁盘
- 解决Centos 6.4 下安装WPS 出现 新建/打开文件闪退的问题
- [leetcode 58] Length of Last Word
- Android有用代码片断(五)
- u-boot分析(五)----I/D cache失效|关闭MMU和cache|关闭看门狗
- 设置java环境变量
- JavaScript简单入门基础教程
- 数据可视化主流研究方向(infoVis收录方向)
- HDOJ Max Sum 1003
- Android有用代码片断(六)
- vs2010下预编译头的作用