letcode434 字符串中的单词数
https://leetcode-cn.com/problems/number-of-segments-in-a-string/
思路比较简单 直接判断单词间的空格就行
class Solution: def countSegments(self, s: str) -> int: flag = False ans = 0 for i in range(len(s)): if s[i]!=' ': flag = True elif s[i]==' ' and flag==True: ans+=1 flag = False if flag==True: ans+=1 return ans