leetcode 434. Number of Segments in a String
int countSegments(string s) { int ret = 0; bool flag = false; for (auto i : s) { if (!flag && i != ' ') { ret++; flag = true; } if (flag && i == ' ') flag = false; } return ret; }
【本文章出自博客园willaty,转载请注明作者出处,误差欢迎指出~】