58. Length of Last Word —— Java
来源:互联网 发布:阿里巴巴阿里云事业部 编辑:程序博客网 时间:2024/06/07 02:40
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
.
PS: str.split(" ") 代表将字符串以“ ”分割。
需要考虑要是分割后没有数组的情况
class Solution { public int lengthOfLastWord(String s) { String[] str = s.split(" "); int len = str.length; if(len<=0) return 0; char[] array = str[len-1].toCharArray(); return array.length; }}
http://blog.csdn.net/carssister/article/details/46835027
以上链接,里面写了java字符串分割的三种方法
阅读全文
0 0
- 58. Length of Last Word —— Java
- Algorithms—58.Length of Last Word
- leetcode-java-58. Length of Last Word
- LeetCode 58. Length of Last Word Java
- (Java)LeetCode-58. Length of Last Word
- [LeetCode] 58. Length of Last Word java
- [leetcode]58. Length of Last Word@Java
- Length of Last Word Java
- Length of Last Word (Java)
- (java)Length of Last Word
- LeetCode——Length of Last Word
- LeetCode——Length of Last Word
- leetcode——Length of Last Word
- LeetCode58——Length of Last Word
- LeetCode58——Length of Last Word
- LeetCode—Length of Last Word
- 58. Length of Last Word
- 58. Length of Last Word
- 《你只是看起来很努力》——阅读笔记
- 51nod 1451 合法三角形 判斜率去重,时间复杂度O(n^2)
- (转)获取 request 中用POST方式"Content-type"是"application/x-www-form-urlencoded;charset=utf-8"发送的 json 数据
- 51nod 1126 求递推序列的第N项 思路:递推模拟,求循环节。详细注释
- (转)java代码发送JSON格式的httpPOST请求
- 58. Length of Last Word —— Java
- 转载自 http://blog.csdn.net/bieleyang/article/details/76973220
- request中获取post的json对象数据content-type=“text/plain”
- 51 nod 1521 一维战舰 时间复杂度O(n),同 Codeforces 567D. One-Dimensional Battle Ships 有详细注释
- 将JavaApplication注册成windows服务
- 软工实践第一篇随笔-准备
- Mybatis insert时返回自增id
- C++ sizeof 误区 大公司面试题
- (转)MyBatis+MySQL 返回插入的主键ID