【字符串】434. 字符串中的单词数
作者:互联网
题目:
解答:
1 class Solution { 2 public: 3 int countSegments(string s) 4 { 5 int res = 0; 6 int flag=1; 7 if (s.size() == 0) 8 { 9 return res; 10 } 11 12 for (int i = 0; i < s.size(); ++i) 13 { 14 if ((s[i]!=' ') && flag) 15 { 16 res++; 17 flag = 0; 18 } 19 if (s[i] == ' ') 20 { 21 flag = 1; 22 } 23 } 24 return res; 25 } 26 };
标签:return,int,res,单词,++,flag,字符串,434,size 来源: https://www.cnblogs.com/ocpc/p/12823131.html