原题地址:https://oj.leetcode.com/problems/length-of-last-word/

题意:

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.

解题思路:Python强大的处理字符串的能力。

代码:

class Solution:
# @param s, a string
# @return an integer
def lengthOfLastWord(self, s):
return len(s.split()[len(s.split())-1]) if s.split() != [] else 0

[leetcode]Length of Last Word @ Python的更多相关文章

  1. Leetcode: Length of Last Word in python

    Length of Last Word Total Accepted: 47690 Total Submissions: 168587     Given a string s consists of ...

  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. 循序渐进学.Net Core Web Api开发系列【3】:WebApi开发概览

    系列目录 循序渐进学.Net Core Web Api开发系列目录 本系列涉及到的源码下载地址:https://github.com/seabluescn/Blog_WebApi 一.概述 目前我们已 ...

  2. Linux驱动之混杂设备(misc)

    字符设备之混杂设备: 定义混杂设备: struct misdevice{ int minor; //为什么这里只有次设备号,因为混杂设备是一种在 /////////////////////////Li ...

  3. 面向对象设计原则 里氏替换原则(Liskov Substitution Principle)

    里氏替换原则(Liskov Substitution Principle LSP)面向对象设计的基本原则之一. 里氏替换原则中说,任何基类可以出现的地方,子类一定可以出现. LSP是继承复用的基石,只 ...

  4. [HDU2138]How many prime numbers

    来源: HDU 2007-11 Programming Contest_WarmUp 题目大意:素数判定. 思路: 事实上暴力判定也可以过,但我还是用了Miller-Rabin算法. 核心思想:利用费 ...

  5. 【原】Redis windows下的环境搭建

    下载地址:https://github.com/dmajkic/redis/downloads 下载下来的包里有两个,一个是32位的,一个是64位的.根据自己的实情情况选择,我的是64bit,把这个文 ...

  6. Spring_Spring@Transactional

    Spring事务的传播行为 在service类前加上@Transactional,声明这个service所有方法需要事务管理.每一个业务方法开始时都会打开一个事务. Spring默认情况下会对运行期例 ...

  7. LPC43xx SGPIO Slice 输入输出连接表

  8. lex yacc flex bison

    lex与yacc是两个在Unix下的分别作词法分析和语法分析的工具, Linux对应flex与bison. windows:http://sourceforge.net/projects/unxuti ...

  9. 使用HTML5和CSS3碎语

    当我们使用HTML5, CSS3,甚至Bootstrap设计网站的时候,有些方面是必须考虑的,比如字体大小,标题大小,行间距,每行字数,字体,颜色,背景图片和文字的搭配,图标,留白和布局......所 ...

  10. WCF中修改接口或方法名称而不影响客户端程序

    本篇接着"从Web Service和Remoting Service引出WCF服务"中有关WCF的部分. 运行宿主应用程序. 运行Web客户端中的网页. 输入内容,点击按钮,能获取 ...