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. Node 操作 MySQL 数据库

    1, 下载 mysql 依赖 => npm -i mysql 2, 写一个核心工具类, 用于获取线程池连接 mysql-util.js // 引入 mysql 数据库连接依赖 const mys ...

  2. java abstract构造函数调用

    构造函数是对象的基本,没有构造函数就没有对象.如果在父类中(这里就是你的抽象类)中显示的写了有参数的构造函数,在子类继承是就必须写一个构造函数来调用父类的构造函数 public abstract cl ...

  3. Set和Map数据

    es6新的数据结构 1.Set:构造函数 const s = new Set ([1,2,3]); console.log(s)//Set(3){1,2,3};[...s];//[1,2,3]cons ...

  4. nginx 和 php超时设置

    nginx.conf ---  http节: keepalive_timeout 600; #客户端浏览器超时时间fastcgi_connect_timeout 600; #php-fpm连接超时时间 ...

  5. day23-类的封装

    1.封装 封装,顾名思义就是将内容封装到某个地方,以后再去调用被封装在某处的内容.所以,在使用面向对象的封装特性时,需要:1)将内容封装到某处2)从某处调用被封装的内容 第一步:将内容封装到某处 cl ...

  6. git学习入门

    git: 安装 git是目前最流行的版本管理系统,分为github(公共开源,代码可随意下载)和gitlib(私有化,企业使用).

  7. SpringBoot配置定时任务的两种方式

    一.导入相关的jar包 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...

  8. 关于cordova 状态栏设置

    https://blog.csdn.net/u011127019/article/details/58104056

  9. js ajax 数据获取

    在js中应用ajax 获取数据的方法,也写一个出来供复习所用 1.建议一个user.json 文件如下,保存名字为 user.json { "name": "huanyi ...

  10. leetcode AC1 感受

    在网上第一个AC还是蛮高兴的,之前试了不少练习编程的方法,感觉不怎么适合自己,在OJ上做题的确是一个能够锻炼的方法. 之前一直研究学习的方法,往简单的说是认知.练习,往复杂的说是,保持足够input, ...