LengthOfLastWord,字符串最后一个子串的长度
2016-08-15 13:32
239 查看
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
' ', 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 LengthOfLastWord { public int lengthOfLastWord(String s) { if(s!=null && !s.trim().equals(""))//equals比较的是内容,==比较的是地址 { //去掉开始和结尾的空格 String[] arr = s.trim().split(" "); int len = arr[arr.length - 1].length(); return len; } return 0; } }
相关文章推荐
- Lettcode_58_Length of Last Word_字符串最后出现单词的长度
- LeeCode 58. Length of Last Word 计算字符串的最后的一个单词的长度
- LeetCode------58. Length of Last Word(字符串中最后一个单词的长度)
- leetcode_58. Length of Last Word 字符串最后一个单词的长度,字符串分词
- leetCode 58.Length of Last Word (最后单词的长度) 解题思路和方法
- [LeetCode]38. Length of Last Word最后单词长度
- LeetCode 58 Length of Last Word(最后单词的长度)
- Length of Last Word --最后单词长度---如何优雅的写代码(重重)
- 字符串中最后一个单词的长度 Length of Last Word
- Length of Last Word 字符串中最后一个单词的长度 @LeetCode
- Length of Last Word 最后个字符长度
- Length of Last Word:字符串中最后一个单词长度
- leetCode 58.Length of Last Word (最后单词的长度) 解题思路和方法
- leetcode 58. Length of Last Word(C语言,计算最后一个单词的长度)19
- 计算字符串最后单词长度
- [leetcode]Length of Last Word (求最后一个单词的长度 C语言实现)
- leetcode:Length of Last Word(求最后一个单词长度)
- 两个子字符串中所共同拥有的长度最大的子序列是多长
- leetCode 58. Length of Last Word 字符串
- Leetcode 58 Length of Last Word 字符串