public class Solution {

public int lengthOfLastWord(String s) {

int count=0;

int len = s.length();

char p[] =s.toCharArray();

if(len>0)

{

for(int i = len-1; i>=0 ;i-- )

{

if(i==0)

{ if(p[i] == ' ')

return count;

else

return len;

}

else if (p[i] != ' ')

{

count = count+1;

}

else if (p[i] == ' ')

{

return count;

}

}

}

else

{

return 0;

}

return 0;}

}