```
def lengthOfLastWord(self, s):
length=len(s)
if length==0:
return 0
for i in range(length-1,-1,-1):
if s[i]!=' ':
break
for j in range(i,-1,-1):
if s[j]==' ':
break
if s[j]!=' ':
return i-j+1
else:
return i-j
```