Given a string s consists of upper/lower-case alphabets and empty space characters ' ', 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) {
if(s.empty()) return ; int len = s.length();
int i = len - ;
int lastLen = ; // 去掉空格
while(s[i] == ' ' && i>=){
--i;
}//while
while(i >= && s[i] != ' '){
++lastLen;
--i;
}//while
return lastLen;
}
};

58. Length of Last Word (String)的更多相关文章

  1. LeetCode练题——58. Length of Last Word

    1.题目 58. Length of Last Word——Easy Given a string s consists of upper/lower-case alphabets and empty ...

  2. [LeetCode] 58. Length of Last Word 求末尾单词的长度

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  3. LeetCode 58. Length of Last Word

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  4. 【LeetCode】58 - Length of Last Word

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  5. 58. Length of Last Word

    题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return t ...

  6. Java [Leetcode 58]Length of Last Word

    题目描述: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return ...

  7. 58. Length of Last Word【leetcode】

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  8. <LeetCode OJ> 58. Length of Last Word

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  9. 58. Length of Last Word(easy, 字符串问题)

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

随机推荐

  1. 将tgz文件解压到指定目录

    转:http://blog.csdn.net/zhenwenxian/article/details/4400404 tar在linux上是常用的打包.压缩.加压缩工具,他的参数很多,折里仅仅列举常用 ...

  2. Linux 用户、权限

    用户:uid  保存在 /etc/passwd 用户分类: 管理员 uid--0 普通用户 --系统用户 uid 1-499 --一般用户  uid 500-60000 组:gid  保存在/etc/ ...

  3. ip黑白名单防火墙frdev的原理与实现

    汤之盘铭曰 苟日新 日日新 又日新 康诰曰 作新民 诗曰 周虽旧邦 其命维新 是故 君子无所不用其极 ——礼记·大学 在上一篇文章<DDoS攻防战 (二) :CC攻击工具实现与防御理论>中 ...

  4. Xe7 System.Json解析数据格式

    一.Demo一 解析嵌套数组 Json数据 {"code":1,"msg":"","data":{"Grade ...

  5. Zookeeper原理架构

    Zookeeper到底是什么!? 学一个东西,不搞明白他是什么东西,哪还有心情学啊!! 首先,Zookeeper是Apache的一个java项目,属于Hadoop系统,扮演管理员的角色. 然后看到官网 ...

  6. jwt-auth错误小结

    我用的是:"tymon/jwt-auth": "1.0.0-rc.1" 根据官方网站http://jwt-auth.readthedocs.io安装,并且ven ...

  7. 【359】scikit learn 官方帮助文档

    官方网站链接 sklearn.neighbors.KNeighborsClassifier sklearn.tree.DecisionTreeClassifier sklearn.naive_baye ...

  8. python使用xlrd 操作Excel读写

    此文章非本人 一.安装xlrd模块 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境. 二.使用介绍 1.导入模块 i ...

  9. Oracle数据文件转移操作

    由于oracle表空间数据文件规划问题导致当前数据文件所在文件系统空间不足,当其他文件系统空间充足情况下,可将数据文件移动到空间充足的文件系统下.本文主要描述Oracle表空间数据文件移动的操作步骤. ...

  10. 四则运算之Right-BICEP单元测试

    一. 这篇博客要对上次实现的四则运算进行单元测试,一是检查上次的程序的实现情况,二是巩固单元测试的相关知识.本次进行单元测试用的是Riget-BICEP方法. Riget-BICEP方法: 1.Rig ...