Skip to content

Instantly share code, notes, and snippets.

@viveksyngh
Created August 8, 2015 18:16
Show Gist options
  • Select an option

  • Save viveksyngh/c3f6a2bd53050ea25dd4 to your computer and use it in GitHub Desktop.

Select an option

Save viveksyngh/c3f6a2bd53050ea25dd4 to your computer and use it in GitHub Desktop.
Finds Length of the Last word, if Last word is not present then return 0
__author__ = 'Vivek'
def lengthOfLastWord(A):
start =0
end = 0
if len(A) == 0 :
return 0
lastLength = 0
curLength = 0
for i in range(len(A)) :
if A[i] != ' ' :
curLength += 1
else :
if curLength != 0 :
lastLength = curLength
curLength = 0
if curLength != 0 :
lastLength = curLength
return lastLength
print(lengthOfLastWord(' '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment