【LeetCode】58. Length of Last Word
2016-03-30 18:58
483 查看
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 len = s.length(); if(len==0) return 0; int re = 0; int i = len-1; while(i>=0 && s[i]==' ') i--; for( ; i >= 0; i--) { if(s[i]!=' ') re++; else break; } return re; } };
相关文章推荐
- WebRTC代码走读(八):代码目录结构
- Python 决定迁移到 GitHub
- Windows内核驱动中操作文件
- Unity3D热更新<三> Me-slua 框架
- paper 50 :人脸识别简史与近期进展
- ALV中将某一字段做为按钮
- mysql启动和关闭外键约束的方法
- Kmp!!!
- 浙大校长吴朝晖在2016年研究生毕业典礼上的讲话:海纳江河传承求是 开物前民笃行创新
- 顶部布局随ScrollView滑动透明度渐变(QQ空间效果)
- sql获取该周的开始结束日期
- EventBus3.0源码解析
- 【NLP】Tika 文本预处理:抽取各种格式文件内容
- IOS-推送通知
- [Xcode]Xcode自动打ipa包脚本
- SQL索引介绍
- 【译】Java 8的新特性—终极版
- Linux具体权限规划之ACL(Access Control List)
- IOS学习之——导航控制器 UINavigationController
- [UWP]一种利用Behavior 将StateTrigger集中管理的方案