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. oracle11g 远程登录数据库

    oracle11g 远程登录数据库比以往的任何版本都要简单,什么也不用做 1.OEM登录 在浏览器中直接输入,远程数据库的OEM网址,当然要把localhost或者主机名改成ip地址   https: ...

  2. USACO Section 3.2: Factorials

    这题注意要保存%10000的数. /* ID: yingzho1 LANG: C++ TASK: fact4 */ #include <iostream> #include <fst ...

  3. vmware 虚拟机 桥接 设置静态 IP

    最简单的方式: 图形界面下,进入设置IP的地方,设置一个静态IP. 然后再转入命令行继续工作.. 不行就 重启  

  4. Java实体书写规范

    ** * 用户角色表 */ public class BaseUserRole implements Serializable { private static final long serialVe ...

  5. 二维码(2)二维码登录原理及Android客户端示例

    1,原理 服务器: 数据库: 建立一个2维码登录的数据表,产生一个登录页时,插入一条记录X,X含将要登录的用户名字段(初始为空),2维码中的数据字段(唯一) 登录页面: 在产生的2维码中包含关键数据Y ...

  6. ZOJ 3367 Counterfeit Money(最大相同子矩阵)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3909 题意:给出两个矩阵A和B,找出最大的相同子矩阵S.输出S的高和 ...

  7. 第四篇 在中国做ERP系统实施你必须知道的一些常识

    1. ERP实施要特别从参与全球竞争的视角指引系统建设.中国社会经历了一个从计划经济体制到市场经济体制的转变.中国加入WTO后,要与国际接轨,要按照世界贸易组织有关的贸易规则开展国际贸易.中国的关税与 ...

  8. [CF580B]Kefa and Company(滑动窗口)

    题目链接:http://codeforces.com/problemset/problem/580/B 某人有n个朋友,这n个朋友有钱数m和关系s两个属性.问如何选择朋友,使得这些朋友之间s最大差距小 ...

  9. CMS 垃圾回收日志

    CMS 垃圾回收日志 https://blogs.oracle.com/poonam/entry/understanding_cms_gc_logs http://www.blogjava.net/D ...

  10. Linux系统信息查看命令

    一.系统 # uname -a #查看内核/操作系统/CPU信息 # head -n 1 /etc/issue #查看操作系统版本 # cat /proc/cpuinfo #查看CPU信息 # hos ...