LeetCode - Length of Last Word

      Java的字符串也很强大。

public class Solution {
    public int lengthOfLastWord(String s) {
        if(s.length() == 0) 
			return 0;
        String[] str = s.trim().split(" ");
        return str[str.length - 1].length();
        
    }
}

 

posted @ 2015-04-03 18:22  Pickle  阅读(127)  评论(0编辑  收藏  举报