Length of Last Word

Total Accepted: 47690 Total Submissions: 168587

 
 

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.

 
Have you met this question in a real interview?
 
class Solution:
# @param {string} s
# @return {integer}
def lengthOfLastWord(self, s):
ret = filter(lambda x: x, s.split(' '))
return len(ret[-1]) if ret else 0

Leetcode: Length of Last Word in python的更多相关文章

  1. [leetcode]Length of Last Word @ Python

    原题地址:https://oj.leetcode.com/problems/length-of-last-word/ 题意: Given a string s consists of upper/lo ...

  2. [LeetCode] 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 the l ...

  4. [LeetCode] Length of Last Word

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

  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] Length of Last Word 字符串查找

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

  7. LeetCode Length of Last Word 最后一个字的长度

    class Solution { public: int lengthOfLastWord(const char *s) { ; string snew=s; ,len=strlen(s); ]; ) ...

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

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

  9. leetcode 题解: Length of Last Word

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

随机推荐

  1. eclipse调试jsp中的scriptlet代码

    在eclipse开发环境下,jsp中的scriptlet代码,也就是<%%>中的java代码,跟普通的java代码一样可以打断点单步调试的! 做个笔记,免得自己忘了!

  2. Tomcat运行DOM4J的时候报ClassNotFoundException

    WEB应用中一个模块用到了DOM4J,加载到TOMCAT中运行,报错如下(给出部分StackTrace): java.lang.ClassNotFoundException: org.dom4j.Do ...

  3. ajax练习习题二三级联动

    异步执行 1数据传输收发数据的时候不用等待对方接受,可以继续发送 2Ajax 在调用处理页面处理数据的时候,下面的代码可以继续执行,效率高 同步执行 1收发数据的时候要等到对方接受的成功,才可以继续发 ...

  4. php克隆 自动加载

    PHP加载 include() 函数 include() 函数可获得指定文件中的所有文本,并把文本拷贝到使用 include 函数的文件中. 例子 1 假设您拥有一个标准的页眉文件,名为 " ...

  5. Android HTTPS(4)直接用SSLSocket,黑名单,客户端证书

    Warnings About Using SSLSocket Directly So far, the examples have focused on HTTPS using HttpsURLCon ...

  6. R语言常用基础知识

    seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)),     length.out = NULL, along.with = NULL, ...

  7. C++ STL 中erase()的使用需要小心

    C++ STL极大的方便了用户编写程序,但是同时一不小心也会犯一些错误,如erase()造成迭代器失效经常会引起错误. 错误示例: std::list< int> List; std::l ...

  8. URAL1355. Bald Spot Revisited

    1355 其实就是求质因子的个数 这样肯定是最多的 注意一下 除到最后不是1的情况 #include <iostream> #include<cstdio> #include& ...

  9. UVa 10054 (打印欧拉回路) The Necklace

    将每个颜色看成一个顶点,对于每个珠子在两个颜色之间连一条无向边,然后求欧拉回路. #include <cstdio> #include <cstring> + ; int G[ ...

  10. POJ 2395 Out of Hay 草荒 (MST,Kruscal,最小瓶颈树)

    题意:Bessie要从牧场1到达各大牧场去,他从不关心他要走多远,他只关心他的水袋够不够水,他可以在任意牧场补给水,问他走完各大牧场,最多的一次需要多少带多少单位的水? 思路:其实就是要让所带的水尽量 ...