58. Length of Last Word
Difficulty: Easy
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:
1 | **Input:** "Hello World" |
Solution
不用split,遍历一下就行了,找到最后一个空格的下标,用字符长度相减
Language: Java
1 | class Solution { |