4ms really breif


  • 3
    S
    int lengthOfLastWord(string s) {
    	stringstream text(s);
    	string str1,str;
    	while (text >> str)
    	{
    		str1 = str;
    	}
    	return str1.size();
    }

  • 0
    G

    you can optimize a little.
    int lengthOfLastWord(string s) {
    stringstream text(s);
    string str;
    while(text>>str);
    return str.size();
    }


  • 0

    Is that standardized/safe? I had seen that and was going to suggest this as well but then I couldn't find it documented and in fact got the impression that it's not standardized/safe.

    Btw, please format your code.


Log in to reply
 

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