找出最后一个词的长度

 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. (引用 )自动化测试报告HTMLtestrunner

    1>下载HTMLTestRunner.py文件,地址为: http://tungwaiyip.info/software/HTMLTestRunner.html   Windows平台: 将下载 ...

  2. 【译】RabbitMQ:"Hello World"

    简介 RabbitMQ是一个消息代理.从本质上讲,它从消息生产者处接收消息,然后传递给消息的消费者.它在消息的生产者和消费者之间根据你指定的规则对消息进行路由.缓存和持久化. RabbitMQ通常使用 ...

  3. linux开机启动

    开机过程指的是从打开计算机电源直到LINUX显示用户登录画面的全过程.分析LINUX开机过程也是深入了解LINUX核心工作原理的一个很好的途径. 启动第一步--加载BIOS 当你打开计算机电源,计算机 ...

  4. Scrum Meeting (Oct. 27 2014)

    软件工程是一门十分有意思的课程,它不仅锻炼了我们开发软件的能力,更是给了我们结队作业的机会,在团队协作中,我们学会了欣赏别人,学会了品鉴自己,学会了如何集思广益凝聚成一个锐意进取的集体.继单人单词查询 ...

  5. javascript 高级程序设计 十二

    1.组合使用原型模式和构造函数模式: 由于原型模式创建对象也有它的局限性------有智慧的人就把原型模式和构造函数模式进行了组合. function Person(name, age, job){/ ...

  6. 第一章 Mybtais的两种启动方式

    Mybatis的两种启动方式如下: 1.xml实现: xml的实现方式中,主要是通过手动创建SqlSession,然后调用session.selectOne()方法实现来实现. 首先是创建Config ...

  7. iOS中POST异步请求

    POST异步请求(代理) 1.遵循<NSURLConnectionDataDelegate> @interface ViewController ()<NSURLConnection ...

  8. checkboxes(复选按钮)

    复选按钮是input的输入框的另一种类型. 每一个复选按钮都应该嵌套进label元素中. 所有关联的复选按钮应该具有相同的name属性. 下面是复选按钮的例子: <label><in ...

  9. ActiveMQ学习笔记

    关键接口和类: ConnectionFactory connectionFactory;//连接工厂 Connection connection;//连接 Session session; Desti ...

  10. day4----生成器,迭代器

    迭代器,生成器,装饰器 1.生成器 通过列表生成式,我们可以直接创建一个列表.但是,受到内存限制,列表容量肯定是有限的.而且,创建一个包含100万个元素的列表,不仅占用很大的存储空间,如果我们仅仅需要 ...