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. VNC+SSH相关应用

    1.安装vnc-server  vncviewer2.执行vncserver  输入密码3.执行vncserver -kill :1 杀死1号屏幕4.修改/root/.vnc/xstartup   u ...

  2. USACO Section 3.2: Feed Ratios

    直接暴力搜 /* ID: yingzho1 LANG: C++ TASK: ratios */ #include <iostream> #include <fstream> # ...

  3. Data Base MySQL的常用命令

       MySQL的常用命令 一.下载地址: http://www.mysql.com 二.安装注意: root默认密码:123456 三.常用命令: 1.创建用户并授权: 创建用户,只能本地访问:cr ...

  4. makefile中的自动化变量 【转】

    转自:http://blog.chinaunix.net/uid-28458801-id-3495215.html 自动化变量 模式规则中,规则的目标和依赖文件名代表了一类文件名:规则的命令是对所有这 ...

  5. 《Linux/Unix系统编程手册》读书笔记3

    <Linux/Unix系统编程手册>读书笔记 目录 第6章 这章讲进程.虚拟内存和环境变量等. 进程是一个可执行程序的实例.一个程序可以创建很多进程. 进程是由内核定义的抽象实体,内核为此 ...

  6. python 内建函数 type() 和 isinstance() 介绍

    Python 不支持方法或函数重载, 因此你必须自己保证调用的就是你想要的函数或对象.一个名字里究竟保存的是什么?相当多,尤其是这是一个类型的名字时.确认接收到的类型对象的身份有很多时候都是很有用的. ...

  7. 2.cadence制板流程[原创]

    1.元器件库(原理图库) 2.原理图 3.DRC检查 4.输出网表 5.PCB封装 6.板子边框 7.导入网表 8.设置约束规则 9.布局,布线,铺铜 10.DRC检查,出丝印,钻孔,出广汇

  8. How to: Write Object Data to an XML File

    This example writes the object from a class to an XML file using the XmlSerializer class. Namespace: ...

  9. Hadoop集群(第10期)_MapReduce与MySQL交互

    2.MapReduce与MySQL交互 MapReduce技术推出后,曾遭到关系数据库研究者的挑剔和批评,认为MapReduce不具备有类似于关系数据库中的结构化数据存储和处理能力.为此,Google ...

  10. hdu4760Good Firewall

    4760 数组模拟就可以了 读的时候可以整数读入 #include <iostream> #include<cstdio> #include<cstring> #i ...