描述
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(const char *s){const string str(s);auto first = first_if(str.rbegin(), str.rend(); ::isalpha);auto last = first_if_not(first , str.rend(), ::isalpha);return distance(first, last);}
};class Solution{
public:int LengthofLastWorld(string str){int res = 0;int length = str.size();int i = 0;int lastspaceindex = 0;while (i<length){if (str[i] == ' ')lastspaceindex = i;i++;}return length - lastspaceindex - 1;}
};

参考资料:

LeetCode题解

字符串 -- 3.15 Length of Last Word -- 图解相关推荐

  1. 字符串中最后一个词组的长度 Length of Last Word

    为什么80%的码农都做不了架构师?>>>    问题: Given a string s consists of upper/lower-case alphabets and emp ...

  2. LeetCode:Length of Last Word

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

  3. LeetCode刷题记录9——58. Length of Last Word(easy)

    LeetCode刷题记录9--58. Length of Last Word(easy) 目录 LeetCode刷题记录9--58. Length of Last Word(easy) 题目 语言 思 ...

  4. LeetCode: 58. Length of Last Word

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

  5. 58. Length of Last Word

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

  6. leetcode 58. Length of Last Word 题解【C++/Java/Python/JS】

    58. 最后一个单词的长度 58. Length of Last Word 题目: 给定一个仅包含大小写字母和空格' ' 的字符串,返回其最后一个单词的长度. 如果不存在最后一个单词,请返回0 . 说 ...

  7. [LeetCode] Length of Last Word - 最后一个单词的长度

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

  8. Leet Code OJ 58. Length of Last Word [Difficulty: Easy]

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

  9. C#LeetCode刷题之#58-最后一个单词的长度(Length of Last Word)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3927 访问. 给定一个仅包含大小写字母和空格 ' ' 的字符串, ...

  10. leetcode python3 简单题58. Length of Last Word

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第五十八题 (1)题目 英文: Given a string s consists ...

最新文章

  1. LeetCode简单题之旋转字符串
  2. 把握数据,驱动未来 | 清华大学大数据研究中心2020年RONG奖学金答辩会成功举办...
  3. python必背内容-python必背函数
  4. Entity Framework 学习高级篇2—改善EF代码的方法(下)
  5. 深入掌握JMS(二):一个JMS例子
  6. rust异步编程--理解并发/多线程/回调/异步/future/promise/async/await/tokio
  7. 在Python中给定包含该项目的列表的情况下查找项目的索引
  8. UCDOS点阵字库提取
  9. TOEFL wordlist 16
  10. 此网站的安全证书有问题
  11. android 图片缩放工具,批量图片缩放软件下载-批量图片缩放 安卓版v1.3.1-PC6安卓网...
  12. Java——求解一元n次方程(V1.0)
  13. 从实战中学前端:打造自己的 html5 文件上传插件
  14. Kile5安装教程和创建一个工程举例【图文STM32F407ZE芯片为例】
  15. Typora导出PDF时,对PDF格式的修改
  16. 2015.04.20,外语,读书笔记-《Word Power Made Easy》 11 “如何辱骂敌人” SESSION 30
  17. 浅析英语五大成分-主谓宾定状
  18. java设置默认值_Spring @Value 设置默认值的实现
  19. 专业化本地项目管理软件-project提供下载
  20. 每日新闻:阿里发布AliOS 2.0;百度与Intel成立联合实验室;微软发布Office 2019;苹果公司收购Shazam...

热门文章

  1. RK3288_Android7.1写一个GPIO驱动控制LED灯亮灭
  2. ASP.NET验证码
  3. weblogic系列漏洞整理 -- 1. weblogic安装
  4. Mac 10.12安装迅雷2.7.2
  5. CAShapeLayer
  6. Jmeter参数化HTTP request中Send Files With The Request的文件路径和文件名
  7. poj1083 解题报告(poj 1083 analysis report)
  8. 使用HTML Help Workshop将HTML转为CHM
  9. 深入浅出InfoPath——如何在项目中引用GAC中的dll文件
  10. 如何对动态创建控件进行验证以及在Ajax环境中的使用