String-58-Length of Last Word
2018-02-08 19:46
323 查看
Description:
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.
Example:
Solution:
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.
Example:
Input: "Hello World" Output: 5
Solution:
class Solution { public int lengthOfLastWord(String s) { if(s == null) return 0; return s.trim().length() - s.trim().lastIndexOf(' ') - 1; } }
相关文章推荐
- [LeetCode 58]Length of Last Word
- Leetcode 58 Length of Last Word
- Leetcode_58_Length of Last Word
- LeetCode_58---Length of Last Word
- LeetCode58----Length of Last Word
- leetcode_58 Length of Last Word C++
- leetcode解题之58 # Length of Last Word Java版
- Leetcode58 Length of Last Word
- leetcode 58:Length of Last Word
- 58 - Length of Last Word
- leetcode 58 Length of Last Word
- [LeetCode]58 Length of Last Word
- Leetcode 58 - Length of Last Word
- Java [Leetcode 58]Length of Last Word
- LeetCode 58 Length of Last Word
- leetcode-58 Length of Last Word
- LeetCode---(58)Length of Last Word
- LeetCode58 Length of Last Word
- 58 Length of Last Word
- [LeetCode 58] Length of Last Word