Simple C/C++ solution


  • 3
    D
    int lengthOfLastWord(string s) {
        size_t pos = s.find_last_not_of(' ');
        return pos - s.substr(0, pos + 1).find_last_of(' ');
    }

Log in to reply
 

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