mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 15:31:43 +08:00
39 lines
1.4 KiB
HTML
39 lines
1.4 KiB
HTML
<p>You are given a string <code>word</code>.</p>
|
|
|
|
<p>Return the <strong>maximum</strong> number of non-intersecting <strong>substrings</strong> of word that are at <strong>least</strong> four characters long and start and end with the same letter.</p>
|
|
|
|
<p>A <strong>substring</strong> is a contiguous <b>non-empty</b> sequence of characters within a string.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">word = "abcdeafdef"</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>The two substrings are <code>"abcdea"</code> and <code>"fdef"</code>.</p>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">word = "bcdaaaab"</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>The only substring is <code>"aaaa"</code>. Note that we cannot <strong>also</strong> choose <code>"bcdaaaab"</code> since it intersects with the other substring.</p>
|
|
</div>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= word.length <= 2 * 10<sup>5</sup></code></li>
|
|
<li><code>word</code> consists only of lowercase English letters.</li>
|
|
</ul>
|