434. Number of Segments in a String

来源:互联网 发布:itools mac airplayer 编辑:程序博客网 时间:2024/06/05 20:45

trival

class Solution {public:    int countSegments(string s) {        int index=0;        int count=0;        while(index<s.size())        {            while(index<s.size()&&s[index]==' ') index++;            if(index<s.size())                count++;            while(index<s.size()&&s[index]!=' ') index++;        }        return count;    }};
0 0