Leetcode Algorithms-58.Length of Last Word

问题地址

Length of Last Word - LeetCode

问题描述

0.jpg

解法

1
2
3
4
5
6
7
8
public class Solution {

public int lengthOfLastWord(String s) {
if (null == s || s.length() == 0) return 0;
String[] a = s.split(" ");
return a.length == 0 ? 0 : a[a.length - 1].length();
}
}
0%