原题地址: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. linux环境下source vimrc提示错误unexpected token `"autocmd"'

    编辑完vimrc之后,使用source /etc/vimrc之后报错: $ source /etc/vimrc bash: /etc/vimrc: line 15: syntax error near ...

  2. Android- SharedPreferences 使用详解

    Android-SharedPreferences 使用详解 参考 https://developer.android.google.cn/reference/android/content/Shar ...

  3. 【WIN10】WIN2D——繪製文字

    先看下截圖: 做了幾個效果:普通.倒影.陰影.歌詞. 普通效果代碼: private void normal_Draw(Microsoft.Graphics.Canvas.UI.Xaml.Canvas ...

  4. zoj 3659 第37届ACM/ICPC 长春赛区现场赛E题 (并查集)

    题意:给出一棵树,找出一个点,求出所有点到这个点的权值和最大,权值为路径上所有边权的最小值. 用神奇的并查集,把路按照权值从大到小排序,然后用类似Kruskal的方法不断的加入边. 对于要加入的一条路 ...

  5. Codeforces Round #369 (Div. 2) C. Coloring Trees 动态规划

    C. Coloring Trees 题目连接: http://www.codeforces.com/contest/711/problem/C Description ZS the Coder and ...

  6. Chrome 开发者工具中的命令菜单

    单 大家对命令菜单(Command Menu)应该都不陌生.目前主流的编辑器中都内置了对该功能的支持.在 Sublime Text 和 Visual Studio Code 中你都可以通过快捷键 Ct ...

  7. Java嵌入式数据库H2学习总结(一)——H2数据库入门

    一.H2数据库介绍 常用的开源数据库有:H2,Derby,HSQLDB,MySQL,PostgreSQL.其中H2和HSQLDB类似,十分适合作为嵌入式数据库使用,而其它的数据库大部分都需要安装独立的 ...

  8. 基于设备树的controller学习(2)

    作者 彭东林 pengdonglin137@163.com 平台 TQ2440 Linux-4.10.17 概述 上一篇大概介绍了一下demo-controller的结构,下面结合驱动分析.   正文 ...

  9. Bootstrap碎语

    这里记录下某段时间Bootstrap的零散碎片. 1.有关Bootstrap的参考网站: ● 官方:http://getbootstrap.com/● 主题:http://bootswatch.com ...

  10. 在ASP.NET MVC中通过勾选checkbox来更改select的内容

    遇到了这样的一个需求:通过勾选checkbox来更改select的内容. 在没有勾选checkbox之前是这样的: 在勾选checkbox之后是这样的: 想通过ajax异步来实现.所以,从控制器拿到的 ...