class Solution:
def countSegments(self, s: str) -> int:
n = 0
f = True
for c in s+" ":
if c == " ":
if not f:
n += 1
f = True
else:
f = False
return n