[3ms] 4 line solution in C++


  • 0
    L

    int lengthOfLastWord(string s)
    {
    // using istringstream to automatically
    //separate the word blocks in the string
    istringstream in(s);
    string word="";
    for(;in>>word;);
    return word.size();
    }


Log in to reply
 

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