```
def countSegments(self, s):
count = 0
length = len(s)
if length == 0:
return count
i = 0
while i < length and s[i] == ' ':
i += 1
while i < length:
while i < length and s[i] != ' ':
i += 1
count += 1
while i < length and s[i] == ' ':
i += 1
return count
```