(String s)
| 1 | public class Solution { |
| 2 | public int lengthOfLastWord(String s) { |
| 3 | int n = s.length() - 1; |
| 4 | int length = 0; |
| 5 | |
| 6 | // Step 1-> skip trailing spaces |
| 7 | while (n >= 0 && s.charAt(n) == ' ') { |
| 8 | n--; |
| 9 | } |
| 10 | |
| 11 | // Step 2-> count last word length |
| 12 | while (n >= 0 && s.charAt(n) != ' ') { |
| 13 | length++; |
| 14 | n--; |
| 15 | } |
| 16 | |
| 17 | return length; |
| 18 | } |
| 19 | } |
nothing calls this directly
no outgoing calls
no test coverage detected