[LintCode] 最后一个单词的长度
2015-06-28 15:57
225 查看
class Solution { public: /** * @param s A string * @return the length of last word */ int lengthOfLastWord(string s) { int len = 0, tail = s.length() - 1; while (tail >= 0 && s[tail] == ' ') tail--; while (tail >= 0 && s[tail] != ' ') { len++; tail--; } return len; } };
相关文章推荐
- T-SQL(一)
- 程序异常总结
- Unity 脚本学习总结
- Mtk Ft6306 touch 驱动
- Windows Server 2012 R2 创建AD域
- 第五章作业
- Spring的HelloWorld
- 加权准确率、目标函数、算法收敛问题
- Centos磁盘管理 进阶篇
- 学习笔记四:boost智能指针:scoped_ptr和shared_ptr
- 求数组中和为某个值的一个组合
- mysql 占用的内存大小
- 幼儿园毕业了~~~
- 文件编码(码表)
- 史上最强算法论战:请不要嘻哈,这是哈希
- 堆栈判断文本括弧是否对称
- 解决iOS Xcode 模拟器键盘不弹出
- mysql的优化
- Swift学习笔记--变量与常量
- SQL数据定义语言