Length of Last Word
class Solution {
public: int lengthOfLastWord(string s) {
int i=;
int len=; while(s[i]&&s[i]==' ') i++; //去掉开头的空格
bool flag = false; while(s[i]){
cout<<len<<endl;
if(s[i]!=' '){
if(flag == true) //如果要计算下一个word,那么len=1
{len=;flag=false;}
else //如果还是当前word,len++
len++;
}
else flag=true; //是空格表示接下来,要统计的另外一个word了
i++;
} return len;
}
};
Length of Last Word的更多相关文章
- [LeetCode] Length of Last Word 求末尾单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- 【leetcode】Length of Last Word
题目简述 Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return ...
- [LeetCode] Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- [LintCode] Length of Last Word 求末尾单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- Java for LeetCode 058 Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- LeetCode 58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- 【Length of Last Word】cpp
题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return t ...
- 【LeetCode】58 - Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- Leetcode: Length of Last Word in python
Length of Last Word Total Accepted: 47690 Total Submissions: 168587 Given a string s consists of ...
- leetcode 题解: Length of Last Word
leetcode: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', re ...
随机推荐
- Java遇见HTML——JSP篇之JavaWeb简介
一.什么是WEB应用程序 Web应用程序是一种可以通过Web(互联网)访问的应用程序.Web应用程序的一个最大好处是用户很容易访问应用程序.用户只需要有浏览器即可,不需要再安装其他软件. 为什么要学习 ...
- canvas保存为data:image扩展功能的实现
[已知]canvas提供了toDataURL的接口,可以方便的将canvas画布转化成base64编码的image.目前支持的最好的是png格式,jpeg格式的现代浏览器基本也支持,但是支持的不是很好 ...
- mysql高负载的问题排查
http://dngood.blog.51cto.com/446195/1150031 log_slow_queries = /usr/local/mysql/var/slow_queries.log ...
- 原来现在很多人都用SignalR来实现Chat Room
今天从一个业余开发的群里,看到有人要求这样一个项目需求: 1,)学员可以通过在线课堂找到自己喜欢的老师和课程. 2,)每个人可以建立自己课堂,每个课堂扣分多个子房间,交流群.设置管理员:有录音功能,可 ...
- Java中几种日志方案
.本文记录Java中几种常用的日志解决方案 0x01 Log4j .这应该是一个比较老牌的日志方案了,配置也比较简单,步骤如下 1)添加对应依赖,比如 Gradle 中 dependencies { ...
- codevs 1206 保留两位小数
http://codevs.cn/problem/1206/ 1206 保留两位小数 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze 题解 查看运行结果 ...
- [原创]java WEB学习笔记84:Hibernate学习之路-- -映射 一对一关系 ,基外键的方式实现
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- SQL静态
静态 1.普通成员普通成员都是属于对象的用对象调用 2.静态成员静态成员是属于类的用类名调用 class FenBi{public int length;//普通成员public string col ...
- .NET: C#: Datetime
比较简单的类,一般用到它的属性.经常会用到的是DateTime.Now和DateTime.Now.TimeOfDay; using System; using System.Collections.G ...
- c++ 中this底层
成员变量设置在一个结构体中, 操作成员变量的成员函数,其实质上就是拥有一个隐藏的 成员变量结构体的地址指针,俗称this指针.