58. Length of Last Word
题目地址:https://leetcode.com/problems/length-of-last-word/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:
Input: "Hello World" Output: 5
class Solution { public int lengthOfLastWord(String s) { String[] str = s.split(" +"); int len = str.length; if (len > 0) return str[len - 1].length(); return 0; } }
========================================Talk is cheap, show me the code=======================================
CSDN博客地址:https://blog.csdn.net/qq_34115899