mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
34 lines
1.3 KiB
HTML
34 lines
1.3 KiB
HTML
<p>An <strong>alphabetical continuous string</strong> is a string consisting of consecutive letters in the alphabet. In other words, it is any substring of the string <code>"abcdefghijklmnopqrstuvwxyz"</code>.</p>
|
|
|
|
<ul>
|
|
<li>For example, <code>"abc"</code> is an alphabetical continuous string, while <code>"acb"</code> and <code>"za"</code> are not.</li>
|
|
</ul>
|
|
|
|
<p>Given a string <code>s</code> consisting of lowercase letters only, return the <em>length of the <strong>longest</strong> alphabetical continuous substring.</em></p>
|
|
|
|
<p> </p>
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> s = "abacaba"
|
|
<strong>Output:</strong> 2
|
|
<strong>Explanation:</strong> There are 4 distinct continuous substrings: "a", "b", "c" and "ab".
|
|
"ab" is the longest continuous substring.
|
|
</pre>
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> s = "abcde"
|
|
<strong>Output:</strong> 5
|
|
<strong>Explanation:</strong> "abcde" is the longest continuous substring.
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
|
<li><code>s</code> consists of only English lowercase letters.</li>
|
|
</ul>
|