class Solution {
public:
int countSegments(string s) {
bool flag = false;
int len = s.length();
int cnt = 0;
for(int i = 0; i < len; i++) {
if(false == flag) {
if(s[i] != ' ') {
cnt++;
flag = true;
}
}
else {
if(' ' == s[i]) {
flag = false;
}
}
}
return cnt;
}
};
434. Number of Segments in a String
最新推荐文章于 2024-10-31 07:15:00 发布