My c++ solution using stringstream


  • 2
    A
    class Solution {
    
        public:
            int lengthOfLastWord(string s) {
                if(s.size() == 0)return 0;
                istringstream istream(s);
                string s1, s2;
                while(istream>>s1){
                    s2 = s1;
                }
                return s2.size();
            }
        };

Log in to reply
 

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