class Solution {

public int lengthOfLastWord(String s) {

```
int n = s.length();
if (n==0) return 0;
int count = 0;
while(s.charAt(n-1) == ' ')
{
n--;
if(n == 0) return 0;
}
while(s.charAt(n-1) != ' ' ){
count++;
n--;
if (n == 0) break;
}
return count;
}
```

}