【LeetCode】58 - Length of Last Word
2015-07-27 22:49
295 查看
Given a string s consists of upper/lower-case alphabets and empty space characters
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 =
return
' ', 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(string s) { int n=s.size()-1; while(n>=0&&s.at(n)&&s.at(n)==' ')n--; int i=0; for(;n>=0&&s.at(n)&&s.at(n)!=' ';n--,i++); return i; } };
相关文章推荐
- 网络协议小结
- log4net 存储到oracle 调试 Could not load type [log4net.Appender.OracleAppender]
- php文件操作系列
- Fragment的基本内容
- 在Ubuntu 14.04 64上安装gevent_zeromq-0.2.5
- 安卓使用Socket发送中文,C语言服务端接收乱码问题解决方案
- guava (三) 集合工具类
- css3立体旋转动画
- Java用DOM操作xml
- Leetcode: Contains Duplicate II
- mysql 指令笔记
- 关于Unity Package无法导入的问题
- Linux命令之文件管理篇
- 如何在Ubuntu 14.04中安装最新版Eclipse
- Ogre 1.9 英文文本显示
- CSS 浮动的16条规则
- 百度地图的一些需要注意的地方
- 代理模式(Proxy pattern)
- 前端CSS规范大全
- N!