// 4ms 98.67% of java

public class Solution {

public int lengthOfLastWord(String s) {

int len = s.length();

int i = len -1;

int empty = 0;

if(s == null || len == 0)

return 0;

while(i>=0 && s.charAt(i)==' '){

i--;

empty++;

}

while(i>=0 && s.charAt(i)!=' ')

i--;

return len- empty - (i+1);

}

}