author: Blankj blog : http://blankj.com time : 2017/05/05 desc :
| 9 | * </pre> |
| 10 | */ |
| 11 | public class Solution { |
| 12 | public int lengthOfLastWord(String s) { |
| 13 | int p = s.length() - 1; |
| 14 | while (p >= 0 && s.charAt(p) == ' ') p--; |
| 15 | int end = p; |
| 16 | while (p >= 0 && s.charAt(p) != ' ') p--; |
| 17 | return end - p; |
| 18 | } |
| 19 | |
| 20 | public static void main(String[] args) { |
| 21 | Solution solution = new Solution(); |
| 22 | System.out.println(solution.lengthOfLastWord("word ")); |
| 23 | System.out.println(solution.lengthOfLastWord("hello world")); |
| 24 | } |
| 25 | } |
nothing calls this directly
no outgoing calls
no test coverage detected