原题地址: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. C# Activex调用USB摄像头--附带源码

    前言 最近在整理一些自己写过的东西,也算是重新熟悉一下并且优化一下吧. 需求:获取本地USB摄像头视频显示,并且获取图片数据给底层做人脸识别. 记得当时直接采用H5已经做好了,调试好了....结果放上 ...

  2. java go

    熟练掌握java技术,对多线程.数据结构有清晰的认识: 熟悉MySQL/Oracle数据库,熟悉关系数据库应用设计开发: 熟悉Spring/MyBatis/Freemarker等一种或者多种框架: j ...

  3. 发布Web端

    1.右键发布 2.配置文件,选择自定义 3.填写配置名称 4.选择本地目录 5.最后发布

  4. BZOJ.1011.[HNOI2008]遥远的行星(思路 枚举)

    题目链接 设当前为\(i\),令\(j=\lfloor a*i\rfloor\),\(1\sim j\) 即为对\(i\)有贡献的行星,这一区间的答案应为\[f[i]=M_i*\sum_{k=1}^j ...

  5. Tomcat无法启动8005端口,提示:java.net.ConnectException: 拒绝连接 (Connection refused)

    修改$JAVA_HOME/jre/lib/security/Java.security 文件中 securerandom.source 配置项: 将 securerandom.source=file: ...

  6. GitLab查询当前版本

    gitlab-rake gitlab:env:info 其实还有很多方法可以参考GitLab的帮助文档:https://docs.gitlab.com/omnibus/README.html 参考: ...

  7. Consul + fabio 实现自动服务发现、负载均衡 - DockOne.io

    Consul + fabio 实现自动服务发现.负载均衡 - DockOne.io   http://dockone.io/article/1567

  8. 7款精美HTML5应用

    1,HTML5/jQuery雷达动画图表图表配置十分简单 分享一款很特别的HTML5图表,它是利用HTML5和jQuery的雷达动画图表,图表数据在初始化的时候带有一定动画. 在线演示         ...

  9. 关于toString方法的重写工具ToStringBuilder

    原文:https://blog.csdn.net/zhaowen25/article/details/39521899# apache的commons-lang3的工具包里有一个ToStringBui ...

  10. uifont 字体详解

    时间2013-06-04 11:26:33 CSDN博客原文  http://blog.csdn.net/u010013695/article/details/9020611 我们在开发中很多时候要设 ...