Python easy solution using strip


#1

def lengthOfLastWord(self, A):
if not(A and A.strip()):
return 0
lst=list(A.split())
n=len(lst)-1
s=lst[n]
return len(s)