LeetCode——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
.
中文:给定一个字符串,包括大写/小写字母和空格字符,返回字符串中最后一个单词的长度。
假设最后一个单词不存在,返回0.
注意:一个单词被定义为仅包括非空字符的字符序列。
比如:
给定 s="Hello World",
返回 5.
此题可能是leetcode上面的最简单的一道题了。
Java:
public int lengthOfLastWord(String s) {
if(s.trim().equals(""))
return 0;
String[] str = s.split("\\s+");
int len = str.length;
return str[len-1].length();
}
LeetCode——Length of Last Word的更多相关文章
- [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 @ 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 in python
Length of Last Word Total Accepted: 47690 Total Submissions: 168587 Given a string s consists of ...
- [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 题解: Length of Last Word
leetcode: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', re ...
- 【一天一道LeetCode】#58. Length of Last Word
一天一道LeetCode系列 (一)题目 Given a string s consists of upper/lower-case alphabets and empty space charact ...
随机推荐
- java 汉字转拼音
先决条件: pinyin4j.jar(Pinyin4j是一个流行的Java库,支持中文字符和拼音之间的转换.拼音输出格式可以定制.) 下载地址:http://pan.baidu.com/share/l ...
- UITextView 限制输入字数
尊重原创 http://blog.csdn.net/fengsh998/article/details/45421107 对于限制UITextView输入的字符数.相信大家在网上见得最多的是实现UI ...
- javascriptDOM编程艺术_学习笔记_知识点 动态创建标记
传统技术:document.write 和 innerHTML 深入剖析DOM方法:createElement.createTextNode.appendChild 和 insertBefore ...
- php基础知识(有代码有注释)
回顾 数组: 数据的组合 数组定义: 三种方式(常用array()) 数组访问: 下标 数组分类: 关联数组, 索引数组和混合数组 数组循环遍历: foreach遍历(foreach原理) 二维数组: ...
- win7 原版下载&激活
参考http://bbs.ithome.com/thread-478939-1-1.html品牌机 win7 32 位系下载http://bbs.ithome.com/forum.php?mod=vi ...
- USB3.0 和usb 2.0的区别
USB3.0拥有10倍于USB2.0的速度,可惜DIY“江湖”险恶,如果咱们不掌握如何识别USB3.0的方法,很容易被JS忽悠.何况,USB3.0主板不等于USB3.0机箱,很多朋友在选购时都忽略了一 ...
- zookeeper leader作用
一个zookeeper 集群 只有一个leader: 类似master/slave模式 客户端提交请求之后,先发送到leader,leader作为接收者,广播到每个server 在folloer上创建 ...
- HTTP基本协议(查看网页代码)
此示例已实现查看网页的代码来理解HTTP基本协议: (返回的是百度首页的网页代码) import java.io.BufferedReader; import java.io.IOException; ...
- pyrailgun 0.24 : Python Package Index
pyrailgun 0.24 : Python Package Index pyrailgun 0.24 Download pyrailgun-0.24.zip Fast Crawler For Py ...
- HDU1284钱币兑换问题( 母函数打表)
题意:在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法.请你编程序计算出共有多少种兑法. 原题http://acm.hdu.edu.cn/showproblem.php?pid=128 ...