class Solution {
public:
int countSegments(string s) {
int res = 0;
for (int i = 0; i<s.length(); i++) {
if (s[i]!=' '&& (s[i+1]==' '|| i==s.length()-1)) {
res++;
}
}
return res;
}
};
Number of Segments in a String
Copyright © 2017 Powered by LZH, Theme used GitHub CSS.