Concise C++ Solution (using istringstream)


  • 0
    W
    int countSegments(string s) {
            int count = 0;
            istringstream is(s); 
            for(string temp; is >> temp;)
                if(!temp.empty()) count++;
            return count;
        }
    

Log in to reply
 

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