leetcode 434. Number of Segments in a String

    int countSegments(string s) {
        int ret = 0;
        bool flag = false;
        for (auto i : s) {
            if (!flag && i != ' ') {
                ret++;
                flag = true;
            }
            if (flag && i == ' ')
                flag = false;
        }
        return ret;
    }

 

posted on 2018-02-26 11:12  willaty  阅读(95)  评论(0编辑  收藏  举报

导航