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 ...
随机推荐
- git的简单使用
Git-csm.com 安装git http://www.git-scm.com/download [liujianzuo@mylab ~]$ yum install git 已加载插件:faste ...
- C# WebBrowser控件 模拟登录 抓取数据
参考博客:C#中的WebBrowser控件的使用 参考博客:C#中利用WebBrowser控件,获得HTML源码 一.问题点: 1.模拟登录后,如果带有嵌套的iframe嵌套,不好读取iframe内容 ...
- java版本的sqlHelper
以下版本的sqlHelper可以支持普通的DDL,DML和查询语句,对于连接池,事务等的支持还有待改进 1)将数据库连接相关信息存储为属性文件,如database.properties,建立DataB ...
- appcon 图标打包
ERROR ITMS-90022: "Missing required icon file. The bundle does not contain an app icon for iPho ...
- php扩展mssql.so连接sqlserver2008
1.安装配置freetds wget http://mirrors.xmu.edu.cn/ubuntu/archive/pool/main/f/freetds/freetds_0.82.orig.t ...
- oc 正则图片<img /> 标签
-(NSString *)getImageAttributeValue:(NSString *)content attributeKey:(NSString *)key { NSString *reg ...
- uiwebview加载中文URL
uiwebview加载中文URL _paperGamePath = [_paperGamePath stringByAddingPercentEscapesUsingEncoding:NSUTF8St ...
- SuSE Apache2 VirtualHost Build
1,linux version:openSuSE 12.1 2,add ServerName to DNS(johv.ts.com ,use the same IP) 3,mkdir /srv/www ...
- eclipse Project facet Java version 1.8 is not supported.
在移植eclipse项目时,如果遇到 “Project facet Java version 1.7 is not supported.” 项目中的jdk1.7不支持.说明项目是其他版本jdk编译的, ...
- lcd 图片
硬件平台:mini2440 软件环境:UCOS2 .ADS1.2 . LCD彩色图片转换工具BMP_to_H工具bmp2h LCD彩色图片转换工具BMP_to_H工具文件夹下的使用说明 在S3C241 ...