Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created February 7, 2018 14:29
Show Gist options
  • Save s4553711/c69094f1a2a324114fbd380e09a76cb7 to your computer and use it in GitHub Desktop.
Save s4553711/c69094f1a2a324114fbd380e09a76cb7 to your computer and use it in GitHub Desktop.
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