Friday, November 27, 2015

[leetcode]Length of Last Word

1
2
3
4
5
6
7
8
public class Solution {
    public int lengthOfLastWord(String s) {
        s = s.trim();
        if (s.equals("")) return 0;
        String[]get = s.split(" ");
        return get[get.length-1].length();
    }
}

No comments:

Post a Comment