mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 15:31:43 +08:00
update
This commit is contained in:
28
leetcode/problem/number-of-segments-in-a-string.html
Normal file
28
leetcode/problem/number-of-segments-in-a-string.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<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> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "Hello, my name is John"
|
||||
<strong>Output:</strong> 5
|
||||
<strong>Explanation:</strong> The five segments are ["Hello,", "my", "name", "is", "John"]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "Hello"
|
||||
<strong>Output:</strong> 1
|
||||
</pre>
|
||||
|
||||
<p> </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>
|
Reference in New Issue
Block a user