public class Solution {
public int lengthOfLastWord(String s) {
if (s == null || s.length() == 0) {
return 0;
}
int len = s.length(), j = len - 1;
while (j >= 0 && s.charAt(j) == ' ') j--;
if (j < 0) {
return 0;
}
int count = 0;
while (j >= 0 && s.charAt(j) != ' ') {
count++;
j--;
}
return count;
}
}