Number of Segments in a String LeetCode solution in C++

1
class Solution {
2
public:
3
int countSegments(string s) {
4
if (s == "") return 0;
5
int res = 0, flag = 0;
6
for (int i = 0; i < size(s); i++) {
7
if (s[i] != ' ') {
8
i++;
9
while (i < size(s) and s[i] != ' ') {
10
i++;
11
}
12
res++;
13
}
14
}
15
return res;
16
}
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0