You should learn stringstream in this problem


  • 0
    B
      int lengthOfLastWord(string s) {
            if(s == "")return 0;
            stringstream str(s);
            string a;
            while(!str.eof())str >> a;
            return a.size();
        }
    

Log in to reply
 

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