Created
August 8, 2015 18:16
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __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