Length of Last Word
2016-05-30 00:22
204 查看
Given a string s consists of upper/lower-case alphabets and empty space characters
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 =
return
public class Solution {
public int lengthOfLastWord(String s) {
return s.trim().length()-s.trim().lastIndexOf(" ")-1;
}
}
' ', 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.
public class Solution {
public int lengthOfLastWord(String s) {
return s.trim().length()-s.trim().lastIndexOf(" ")-1;
}
}
相关文章推荐
- LeetCode 11 Container With Most Water
- POJ3061Subsequence
- PHP异常类
- 20160530
- JS基础语法(循环语句)
- Unity3D-5.3.5发布VR项目到Android
- 并查集 最大集合并且按顺序输出集合内元素。
- 第三周团队博客
- 2016安徽省赛 - 木条染色 离散化+线段树
- Linux密码故障排除详解
- mybatis中接口没有实现类的动态代理探究
- hdu1058
- 约束的传播
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2
- Paragraph Vector在Gensim和Tensorflow上的编写以及应用
- ESP8266-SDK如何设置静态IP
- volley+Express实现简单的客户端服务器通信
- Factorial Trailing Zeroes
- [置顶] 解决NDK开发中Eclipse报错“Unresolved inclusion jni.h”的最终方法
- CSS3盒模型温故