leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0434.cpp (430B)
0 class Solution {
1 public:
2 int countSegments(const string &s) const {
3 const int n = size(s);
4 int res = 0;
6 for (int i = 0; i < n;) {
7 if (s[i] != ' ') {
8 while (i < n && s[i] != ' ')
9 i++;
10 res++;
11 } else {
12 while (i < n && s[i] == ' ')
13 i++;
14 }
15 }
17 return res;
18 }
19 };