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 ...
随机推荐
- android handler调用post方法阻塞
1.试下用postDelayed(Runnable a, int time),因为post把消息放到Looper中就返回,但Looper中没有其他消息又会被立刻取出来执行,这样就有可能做了run中的操 ...
- 8款实用Sublime text 3插件推荐
Sublime Text作为一个尽为人知的代码编辑器,其优点不用赘述.界面整洁美观.文本功能强大,且运行速度极快,非常适合编写代码,写文章做笔记.Sublime Text还支持Mac.Windows和 ...
- 再探Java基础——throw与throws
http://blog.csdn.net/luoweifu/article/details/10721543 异常处理机制 异常处理是对可能出现的异常进行处理,以防止程序遇到异常时被卡死,处于一直等待 ...
- nginx + keepalived 双机热备
序 双机热备是指两台机器都在运行,但并非两台机器同时在提供服务. 当提供服务的一台出现故障的时候,另外一台会马上自动接管并且提供服务,且切换的时间非常短. keepalived的工作原理是VRRP—— ...
- Git和SSH协议
SSH(安全外壳协议)为Secure Shell的缩写,由IETF的网络工作小组(Network Working Group)所制定:SSH为建立在应用层和传输层基础上的安全协议.SSH是目前较可靠, ...
- ARC机制下组合关系
// // Person.h // 01-autorelease基本概念 // // Created by apple on 14-3-18. // Copyright (c) 2014年 a ...
- iOS 蓝牙开发之传输图片
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...
- jquery文字溢出处理,超出变省略号
//文字溢出 $(function(){ $(".d_dt a").each(function(){ var maxwidth =100; if($(this).text().le ...
- ECharts 在同一个页面添加多个图表 并 给图表绑定事件
<!DOCTYPE html> <head> <meta charset="utf-8"> <title>ECharts< ...
- 正确导入android-support-v4.jar的方法
在导入使用了ViewPage,ActionBar,Fragment的工程后出现错误,很有可能是没有导入4.0版本的支持包. 首先在Project->properties->Java Bui ...