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 ...
随机推荐
- 7z usecaes
1. Archive without compressing 7z a -t7z -mx=0 OutputFilename InputFilename Descryption: a: command, ...
- C# 调用VC++的DLL,VC++封装DLL
VS中新建一个动态库项目 文件生成一个工程名对应的.cpp文件,该文件定义 DLL应用程序的导出函数. 工程内新建一个类OutputInt,我用类向导生成,工程中会添加OutputInt.cpp和Ou ...
- Vue.2.0.5-条件渲染
v-if 在字符串模板中,如 Handlebars ,我们得像这样写一个条件块: <!-- Handlebars 模板 --> {{#if ok}} <h1>Yes</h ...
- protocol(协议)的一些要点
//遵循协议的变量声明 //要求你创建的PErson对象必须是遵循了 PersonProtocol Person<PersonProtocol> * p2 = [[Person alloc ...
- php 调用 java 接口
php 需要开启 curl模块 /** HTTP 请求函数封装*/function http_request_cloudzone($url, $data){ //var_dump($url." ...
- 通过SSIS监控远程服务器磁盘空间并发送邮件报警!
由于之前ESB是供应商部署的,且部署在C盘(C盘空间很小,还添加了很多ESB的windows服务日志在C盘,很容易把C盘空间占满,导致ESB服务运行宕机,几乎每隔几周发生一次事故,需要人工干预处理,不 ...
- 解决多线程调用sql存储过程问题
场景: 我们程序现在改成多线程了,我现在需要把临时表中的数据给插入到TABLE_M中,但这时候可能其他的线程也在插入,我就不能用之前我们的方案了(select max(oid) from Tuning ...
- PostgreSQL 非持久化设置(Non-Durable Settings)
Durability is a database feature that guarantees the recording of committed transactions even if the ...
- Leetcode: Word Pattern II
Given a pattern and a string str, find if str follows the same pattern. Here follow means a full mat ...
- 转:Python获取随机数(中文)
下面介绍下random中常见的函数. 前提:需要导入random模块 >>>import random 1.random.random random.random() 用于生成一个0 ...