Leetcode: Length of Last Word
来源:互联网 发布:mac kindle 导出 编辑:程序博客网 时间:2024/05/18 02:56
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
.
public class Solution { public int lengthOfLastWord(String s) { if (s == null || s.length() == 0) { return 0; } int size = s.length(); int i = size - 1; while (i >= 0 && s.charAt(i) == ' ') i--; int count = 0; while (i >= 0 && s.charAt(i) != ' ') { count++; i--; } return count; }}
0 0
- LeetCode: Length of Last Word
- LeetCode Length of Last Word
- LeetCode : Length of Last Word
- [Leetcode] Length of Last Word
- [LeetCode] Length of Last Word
- [LeetCode]Length of Last Word
- [leetcode]Length of Last Word
- Leetcode:Length of Last Word
- LeetCode-Length of Last Word
- [LeetCode] Length of Last Word
- [leetcode] Length of Last Word
- leetcode length of last word
- LeetCode - Length of Last Word
- leetcode:Length of Last Word
- LeetCode:Length of Last Word
- LeetCode | Length of Last Word
- LeetCode - Length of Last Word
- Leetcode: Length of Last Word
- Swift基础--调用第三方OC项目
- HDU 5079(2014 Asia AnShan Regional Contest J)
- 2014秋C++第9周项目4参考-小九九
- 玩转图形学 (二)彩虹
- 2014秋C++第9周项目5参考-循环填充题
- Leetcode: Length of Last Word
- 马上要学习一门新的语言了,并且直接做一个项目,我要在这记录我学习的过程,加油
- C++实践参考解答 穷举法解决组合问题
- hdoj 1164 Eddy's research I
- nyoj1103勇者斗恶龙
- 手机游戏会统治游戏世界么?
- ORACLE纯SQL实现多行合并一行
- unity3d 内部Transparent (透明)shader 代码
- Oracle笔记