Created
February 7, 2018 14:29
-
-
Save s4553711/c69094f1a2a324114fbd380e09a76cb7 to your computer and use it in GitHub Desktop.
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
class Solution { | |
public: | |
int lengthOfLastWord(string s) { | |
int len = 0, tail = s.length() - 1; | |
while (tail >= 0 && s[tail] == ' ') tail--; | |
while (tail >= 0 && s[tail] != ' ') { | |
len++; | |
tail--; | |
} | |
return len; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment