My 4lines ac c++ code with 6ms


  • 1
    Z
    int lengthOfLastWord(string s) {
            int i;int size = s.length();
    		while(s[size-1]==' ')	s.resize(--size);
    		i = s.find_last_of(' ');
    		return (i==-1)?size:size-i-1;
    	}

Log in to reply
 

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