58. Length of Last Word Poison 2022-05-20 1234567891011121314151617class Solution { public int lengthOfLastWord(String s) { int j = s.length() - 1; while (s.charAt(j) == ' ') { j--; } // 此时 j 指向英文字母 int i = j; while (i >= 0 && s.charAt(i) != ' ') { i--; } // 此时 i 指向空格或越界 return j - i; }} References58. Length of Last Word