Leetcode: Length of Last Word in python
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.
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的更多相关文章
- [leetcode]Length of Last Word @ Python
原题地址:https://oj.leetcode.com/problems/length-of-last-word/ 题意: Given a string s consists of upper/lo ...
- [LeetCode] Length of Last Word 求末尾单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- LeetCode——Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- [LeetCode] Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- [Leetcode] Length of last word 最后一个单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters' ', return the le ...
- [LeetCode] Length of Last Word 字符串查找
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- LeetCode Length of Last Word 最后一个字的长度
class Solution { public: int lengthOfLastWord(const char *s) { ; string snew=s; ,len=strlen(s); ]; ) ...
- 【LeetCode】58. Length of Last Word 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 库函数 双指针 单指针 日期 题目地址:https: ...
- leetcode 题解: Length of Last Word
leetcode: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', re ...
随机推荐
- c#对文件进行MD5加密校验
public static string GetFileMd5Hash(string strFileFullPath) { // Create a new instance of the MD5Cry ...
- MySQL —— 程序连接时的驱动名称和URL
CONNECTION_DRIVER : com.mysql.jdbc.Driver CONNECTION_URL : jdbc:mysql://localhost/DB_NAME
- 10.cadence.自定义焊盘的创建[原创]
一.自定义图形焊盘 1.设置环境(面板大小,格点) --- ------ 圆形 Shape > Circular ---- 两个DRC错误,证明图形重合了, 将图形复合一下: --- 椭圆类焊盘 ...
- poj-3176 Cow Bowling &&poj-1163 The Triangle && hihocoder #1037 : 数字三角形 (基础dp)
经典的数塔模型. 动态转移方程: dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+p[i][j]; #include <iostream> #include ...
- Create Entity Data Model
http://www.entityframeworktutorial.net/EntityFramework5/create-dbcontext-in-entity-framework5.aspx 官 ...
- ulimit调优
1. linux的ulimit各种限制之深入分析 http://blog.sina.com.cn/s/blog_59b6af6901011ekd.html 2. Linux下修改ulimit设置的最大 ...
- hdu4760Good Firewall
4760 数组模拟就可以了 读的时候可以整数读入 #include <iostream> #include<cstdio> #include<cstring> #i ...
- 函数mem_pool_create
/********************************************************************//** Creates a memory pool. @re ...
- POJ 1436 (线段树 区间染色) Horizontally Visible Segments
这道题做了快两天了.首先就是按照这些竖直线段的横坐标进行从左到右排序. 将线段的端点投影到y轴上,线段树所维护的信息就是y轴区间内被哪条线段所覆盖. 对于一条线段来说,先查询和它能相连的所有线段,并加 ...
- java基础:数据类型
一:基本数据类型 (1):整数类型 byte,short,int,long (2):浮点类型 float , double (3):布尔类型 boolean 注意: long 类型的变量后面要 ...