Clean C++ 4 lines O(n) solution


  • 0
        int countSegments(string s) {
            s.append(" ");
            int count=0;
            for(string::iterator it=s.begin();it!=s.end();it++) if(*it!=' '&&*(it+1)==' ') count++;
            return count;
        }
    

Log in to reply
 

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