C++ simple solution.


  • 0
    C
    int lengthOfLastWord(string s) {
        int l = s.size()-1, count = 0;
        while (l>=0 && isspace(s[l]))
            l--;
        while (l>=0 && isalpha(s[l])) {
            count++;
            l--;
        }
        return count;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.