class Solution {
public int lengthOfLastWord(String s) {
int length = 0;
for (int i = s.length() - 1; i >= 0; i--) {
if (s.charAt(i) != ' ') {
length++;
} else if (length != 0) {
return length;
}
}
return length;
}
}
02-15
734
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)