C++ simple solution using string stream


  • 0
    Q

    int lengthOfLastWord(string s) {
    stringstream ss(s);
    string lastWord;
    while(ss >>s) //read every word in the string, from beginning to end
    { lastWord = s; }
    return lastWord.length();
    }


Log in to reply
 

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