MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/easy/_0058/Solution.java:11–25  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/05/05 desc :

Source from the content-addressed store, hash-verified

9 * </pre>
10 */
11public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected