扫描每个WORD的长度并记录即可。

 int lengthOfLast(const char *s)
{
//扫描统计每个word的长度
int len = ;
while (*s)
{
if (*s++ != ' ')//注意不管是否满足s都要++
len++;
else if (*s && *s != ' ')
len = ;
} return len;
}

Leetcode 之Length of Last Word(37)的更多相关文章

  1. leetcode 题解: Length of Last Word

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

  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】Length of Last Word

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

  4. Java for LeetCode 058 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

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

  6. Java [Leetcode 58]Length of Last Word

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

  7. LeetCode(48)-Length of Last Word

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

  8. [leetcode]58. Length of Last Word最后一个词的长度

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

  9. 【LeetCode】- Length of Last Word(最后一个单词的长度)

    [ 问题: ] Given a string s consists of upper/lower-case alphabets and empty space characters ' ', retu ...

  10. [leetcode] 18. Length of Last Word

    这个题目很简单,给一个字符串,然后返回最后一个单词的长度就行.题目如下: Given a string s consists of upper/lower-case alphabets and emp ...

随机推荐

  1. BZOJ3195:[JXOI2012]奇怪的道路——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=3195 Description 小宇从历史书上了解到一个古老的文明.这个文明在各个方面高度发达,交通方 ...

  2. [APIO2017]商旅

    link 这题卡我精度,调了一晚上才调对,因为没有想到图还可以不连通 其实可以预处理出好多东西,距离($dis(u,v)$),买卖物品(从$u$到$v$买卖物品的最大利润,例($max{S_{u,i} ...

  3. 【系统设计】432. 全 O(1) 的数据结构

    题目: 使用栈实现队列的下列操作: push(x) -- 将一个元素放入队列的尾部. pop() -- 从队列首部移除元素. peek() -- 返回队列首部的元素. empty() -- 返回队列是 ...

  4. Codeforces Round #329 (Div. 2)A 字符串处理

    A. 2Char time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  5. Codeforces Round #345 (Div. 2) A

    A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  6. Codeforces Round #340 (Div. 2) A

    A. Elephant time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  7. Eureka与zookeeper

    Eureka的优势 1.在Eureka平台中,如果某台服务器宕机,Eureka不会有类似于ZooKeeper的选举leader的过程:客户端请求会自动切换到新的Eureka节点:当宕机的服务器重新恢复 ...

  8. ACM2647拓扑排序逆运算

    2647题是对工人排序问题,不是从头到尾排序,而是从尾到头排序: 代码中用到vector和queue容器,权当练习. 用广搜进行拓扑排序的逆运算. #include<iostream> # ...

  9. ssm项目,web容器无法初始化项目

    在web.xml中配置加载spring时,发现项目无法运行:而去掉spring的配置时,项目可以被初始化. 此时应考虑到spring的配置文件中存在错误,以至于web容器无法对项目成功初始化,在web ...

  10. 51Nod 1003 阶乘后面0的数量 | 思维

    题意:n的阶乘后面0的个数,如果直接算出阶乘再数0的数量一定会超时的. 因为10=2*5,所以求出5贡献的次数就行. #include "bits/stdc++.h" using ...