找出最后一个词的长度

 class Solution {
public:
int lengthOfLastWord(string s) {
int a = , l = , b = ;
while((b = s.find(" ", a)) != string::npos){
if(b - a > ) l = b - a;
a = b + ;
}
if(a == s.size()) return l;
else return s.size() - a;
}
};

Leetcode 58 Length of Last Word 字符串的更多相关文章

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

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

  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. Java [Leetcode 58]Length of Last Word

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

  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. leetCode 58.Length of Last Word (最后单词的长度) 解题思路和方法

    Length of Last Word  Given a string s consists of upper/lower-case alphabets and empty space charact ...

  6. LeetCode: 58. Length of Last Word(Easy)

    1. 原题链接 https://leetcode.com/problems/length-of-last-word/description/ 2. 题目要求 给定一个String类型的字符串,字符串中 ...

  7. Leetcode 58 Length of Last Word 难度:0

    https://leetcode.com/problems/length-of-last-word/ int lengthOfLastWord(char* s) { int ans = 0; int ...

  8. 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 ...

  9. 【LeetCode】58. Length of Last Word 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 库函数 双指针 单指针 日期 题目地址:https: ...

随机推荐

  1. C# webApi 与 AngularJs 实现增删改Demo 讲解(一)

    公司在使用webAPI+AngularJs+SlcikGrid进行产品开发,自己也是初学Angular,就做了一个Demo,实现增删改功能,希望可以帮助大家. 界面如同所示:  数据库一张单表很简单, ...

  2. git 使用命令总结

    当远程仓库有README.md的时候我们创建的工程里没有这个文件这时候你提交的仓库和远程的不一致就会导致提交被拒绝 此时我们可以先拉取主干到本地的temp分支  然后和本地的master分支合并 通过 ...

  3. Spring+MyBatis多数据源配置实现

    最近用到了MyBatis配置多数据源,原以为简单配置下就行了,实际操作后发现还是要费些事的,这里记录下,以作备忘 不多废话,直接上代码,后面会有简单的实现介绍 jdbc和log4j的配置 #定义输出格 ...

  4. 2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  5. IOS网络请求原理

    1,为什么要用到网络,  只有通过网络跟外界进行数据交互,数据更新,应用才能保持哦新鲜.活力 如果没有网络,也就缺少数据变化.变成一滩死水. 2, 良好的移动网络应用 = 良好的UI + 良好的用户体 ...

  6. su - root 报su: incorrect password的错误

    检查/bin/下面的文件的组属 和 sh 文件 的权限 是否有问题 例如:-rwxr-xr-x. 1 weblogic dba 34904 Jul 15  2011 /bin/su1   修改这个文件 ...

  7. Web开发中的主要概念

    一.Web开发中的主要概念1.静态资源:一成不变的.html.js.css2.动态资源:JavaWeb.输出或产生静态资源.(用户用浏览器看到的页面永远都是静态资源) 3.JavaEE:十三种技术的集 ...

  8. 【kd-tree】bzoj1941 [Sdoi2010]Hide and Seek

    枚举每个点,计算离他最近的和最远的点. #include<cstdio> #include<cmath> #include<algorithm> using nam ...

  9. node应用场景

    2.1 Web开发:Express + EJS + Mongoose/MySQL express 是轻量灵活的Nodejs Web应用框架,它可以快速地搭建网站.Express框架建立在Nodejs内 ...

  10. ubuntu Screen 的比较详细的命令

    Linux Screen Commands For Developers 转自:http://fosshelp.blogspot.com/2014/02/linux-screen-commands-f ...