• 题目描述：
• 示例:
• 解法：

# 示例:

``````    输入: "Hello, my name is John"
输出: 5``````

# 解法：

``````class Solution {
public:
int countSegments(string s) {
int res = 0;
int sz = s.size();
int i = 0, j = 0;
while(i < sz){
while(j < sz && s[j] != ' '){
j++;
}
if(i != j){
res++;
}
j++;
i = j;
}
return res;
}
};``````

## [Swift]LeetCode806. 写字符串需要的行数 | Number of Lines To Write String

We are to write the letters of a given string S, from left to right into lines. Each line has maximum width 100 units, and if writing a letter would cause the width of the line to exceed 100 units, it is written on the next line. We are given an arra

## [LeetCode] 151. Reverse Words in a String 翻转字符串中的单词

Given an input string, reverse the string word by word. For example,Given s = "the sky is blue",return "blue is sky the". Update (2015-02-12):For C programmers: Try to solve it in-place in O(1) space. Clarification: What constitutes a

## #Leetcode# 434. Number of Segments in a String

https://leetcode.com/problems/number-of-segments-in-a-string/ Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters. Please note that the string does not contain any non-printable cha