题目:
题解:
class Solution {
public:
int countSegments(string s) {
int segmentCount = 0;
for (int i = 0; i < s.size(); i++) {
if ((i == 0 || s[i - 1] == ' ') && s[i] != ' ') {
segmentCount++;
}
}
return segmentCount;
}
};