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.

Hide Tags

String

class Solution {
public:
int lengthOfLastWord(const char *s) {
if(s==NULL)
return ;
int len=;
const char *start = s;
while(*s!='\0'){
if(*s==' '){
int le=s-start;
if(le!=)
len=le;
start=s+;
s++;
}else
s++;
}
int le=s-start;
if(le!=)
len=le;
return len;
}
};

Length of Last Word输出最后单词的字母个数的更多相关文章

  1. map集合修改其中元素 去除Map集合中所有具有相同值的元素 Properties长久保存的流操作 两种用map记录单词或字母个数的方法

    package com.swift.lianxi; import java.util.HashMap; import java.util.Iterator; import java.util.Map; ...

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

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

  3. lintcode:Length of Last Word 最后一个单词的长度

    题目: 最后一个单词的长度 给定一个字符串, 包含大小写字母.空格' ',请返回其最后一个单词的长度. 如果不存在最后一个单词,请返回 0 . 样例 给定 s = "Hello World& ...

  4. 58. Length of Last Word最后一个单词的长度

    [抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: "b a " 最后一位是空格,可能误 ...

  5. [Leetcode] Length of last word 最后一个单词的长度

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

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

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

  7. [LintCode] Length of Last Word 求末尾单词的长度

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

  8. 058 Length of Last Word 最后一个单词的长度

    给定一个字符串, 包含大小写字母.空格 ' ',请返回其最后一个单词的长度.如果不存在最后一个单词,请返回 0 .注意事项:一个单词的界定是,由字母组成,但不包含任何的空格.案例:输入: " ...

  9. [Swift]LeetCode58. 最后一个单词的长度 | Length of Last Word

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

随机推荐

  1. PAT甲级——A1032 Sharing

    To store English words, one method is to use linked lists and store a word letter by letter. To save ...

  2. C#绘制渐变线条

    Brush brush = , ), , ), Color.Blue, Color.White); e.Graphics.FillRectangle(brush, this.ClientRectang ...

  3. java mybatis 参数问题

  4. 系统io统计

      $ cat /proc/diskstats sda sda1 sda2 gg- gg- gg- 主号 次号 名称 成功读 合并读 扇区读 读时间   每一列的含义分别为: 第一列为 设备号 (nu ...

  5. Eclipse:Eclipse所有发布版本的下载地址

    官方镜像:http://eclipse.mirror.rafal.ca/technology/epp/downloads/release/ 国内镜像:http://mirrors.neusoft.ed ...

  6. MySQL系列(五)--二进制日志对主从复制的影响

    MySQL复制是基于主库上的二进制日志来完成,复制是异步的,可能存在延迟 MySQL日志分为: 1.服务层日志:二进制日志.通用日志.慢查日志 2.存储引擎层日志:innodb中重做日志和回滚日志 二 ...

  7. [Array]122. Best Time to Buy and Sell Stock II(obscure)

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  8. tinkcmf视频上传大小限制

    /application/Common/Common/function.php 找到upload_max_filesize把后面的数值改成合适的大小(单位是KB)

  9. git出现“The file will have its original line endings in your working directory”错误

    一.现象: git add *时出现如下现象: The file will have its original line endings in your working directory 解决: G ...

  10. VS插件集合

    VS的强大不仅仅在于VS本身的强大. 同时,也有很多好用的插件,可以帮助我们更好的编辑代码, 提高效率. https://marketplace.visualstudio.com/search?tar ...