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. java Comparable和Comaprator的对比

    Comparable使一个class具备不同实例间进行比较的行为.这些对象的集合,可作为Collections.sort或Arrays.sort的参数 Comparator可以看成一种算法的实现,将算 ...

  2. MimeTypes list

    application/acad *.dwg AutoCAD-Dateien (nach NCSA) application/applefile AppleFile-Dateien applicati ...

  3. 用任务管理器画CPU正弦曲线

    这个最初是在microsoft的<编程之美>中看到的,用你的程序来控制CPU的使用率. 首先是要求写一个用来实现CPU使用率为50%程序. 这个还是很好实现的,只要让你的程序忙的时间课空闲 ...

  4. js中indexOF和lastIndexOf

    indexOFindexOf() 方法返回某个指定的字符串值在字符串中首次出现的位置(从左向右).没有匹配的则返回-1,否则返回首次出现位置的字符串的下标值. var src="images ...

  5. 生成24位字符串ID__IdGenerator.java

    此工具类用于生成24位字符串ID,唯一不重复.直接通过 IdGenerator.get() 获取. 源码如下:(点击下载源码 - IdGenerator.java ) import java.net. ...

  6. Ext的正则表达式

    http://www.cnblogs.com/azai/archive/2010/12/31/1923140.html   今天看到一篇关于Extjs正则表达式比较系统的总结. 使用extJs时能常用 ...

  7. Mac 版 QQ 可直接访问 iPhone 的相册 ?!

    在QQ的聊天窗口中,点击 发送图片 的按钮,会有两个选择项,其中一个就是 从iPhone相册中选取 ,如图 点击  从iPhone相册中选取 后,iPhone上的QQ会收到一条消息 “请选择要上传的照 ...

  8. 查看linux系统常用的命令,Linux查看系统配置常用命令

    一.linux CPU大小  cat /proc/cpuinfo |grep "model name" && cat /proc/cpuinfo |grep &qu ...

  9. MTK平台缩写

    HSPA:High Speed Packet Access smartphone application processor,高速分组接入的智能手机应用程序处理器 META mode:Mobile E ...

  10. vs中常用的快捷键

    VS中常用的快捷键: ctrl+s         保存 ctrl+Shift+S   保存所有VS中打开的所有文件 ctrl+O         打开新文件 ctrl+Shift+O   打开项目 ...