标签:style blog java color strong io
[ 问题: ]
Given a string s consists of upper/lower-case alphabets and empty space characters ‘ ‘, return the length of last word in the string.[ 分析 : ]
A word is defined as a character sequence consists of non-space characters only.[ 解法: ]
public class Solution { public int lengthOfLastWord(String s) { if (s != null && !s.trim().equals("")) { String[] arr = s.trim().split(" "); int length = arr[arr.length - 1].length(); return length; } return 0; } public static void main(String[] args) { String s = "leet code"; System.out.println(new Solution().lengthOfLastWord(s)); } }
【LeetCode】- Length of Last Word(最后一个单词的长度),码迷,mamicode.com
【LeetCode】- Length of Last Word(最后一个单词的长度)
标签:style blog java color strong io
原文地址:http://blog.csdn.net/zdp072/article/details/24818143