Class Solution
java.lang.Object
g0401_0500.s0434_number_of_segments_in_a_string.Solution
434 - Number of Segments in a String.<p>Easy</p>
<p>Given a string <code>s</code>, return <em>the number of segments in the string</em>.</p>
<p>A <strong>segment</strong> is defined to be a contiguous sequence of <strong>non-space characters</strong>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “Hello, my name is John”</p>
<p><strong>Output:</strong> 5</p>
<p><strong>Explanation:</strong> The five segments are [“Hello,”, “my”, “name”, “is”, “John”]</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “Hello”</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 <= s.length <= 300</code></li>
<li><code>s</code> consists of lowercase and uppercase English letters, digits, or one of the following characters <code>"!@#$%^&*()_+-=',.:"</code>.</li>
<li>The only space character in <code>s</code> is <code>' '</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
countSegments
-