Skip to content

Commit c46e962

Browse files
authored
Merge pull request #1290 from 0xff-dev/2414
Add solution and test-cases for problem 2414
2 parents e04255e + b3873f7 commit c46e962

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

leetcode/2401-2500/2414.Length-of-the-Longest-Alphabetical-Continuous-Substring/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# [2414.Length of the Longest Alphabetical Continuous Substring][title]
22

3-
> [!WARNING|style:flat]
4-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5-
63
## Description
4+
An **alphabetical continuous string** is a string consisting of consecutive letters in the alphabet. In other words, it is any substring of the string `"abcdefghijklmnopqrstuvwxyz"`.
5+
6+
- For example, `"abc"` is an alphabetical continuous string, while `"acb"` and `"za"` are not.
7+
8+
Given a string `s` consisting of lowercase letters only, return the length of the **longest** alphabetical continuous substring.
79

810
**Example 1:**
911

1012
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
13+
Input: s = "abacaba"
14+
Output: 2
15+
Explanation: There are 4 distinct continuous substrings: "a", "b", "c" and "ab".
16+
"ab" is the longest continuous substring.
1317
```
1418

15-
## 题意
16-
> ...
19+
**Example 2:**
1720

18-
## 题解
19-
20-
### 思路1
21-
> ...
22-
Length of the Longest Alphabetical Continuous Substring
23-
```go
2421
```
25-
22+
Input: s = "abcde"
23+
Output: 5
24+
Explanation: "abcde" is the longest continuous substring.
25+
```
2626

2727
## 结语
2828

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(s string) int {
4+
ans := 1
5+
cur := 1
6+
for i := 1; i < len(s); i++ {
7+
if s[i] == s[i-1]+1 {
8+
cur++
9+
} else {
10+
cur = 1
11+
}
12+
ans = max(ans, cur)
13+
}
14+
return ans
515
}

leetcode/2401-2500/2414.Length-of-the-Longest-Alphabetical-Continuous-Substring/Solution_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14-
expect bool
13+
inputs string
14+
expect int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", "abacaba", 2},
17+
{"TestCase2", "abcde", 5},
1918
}
2019

2120
// 开始测试
@@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
3029
}
3130
}
3231

33-
// 压力测试
32+
// 压力测试
3433
func BenchmarkSolution(b *testing.B) {
3534
}
3635

37-
// 使用案列
36+
// 使用案列
3837
func ExampleSolution() {
3938
}

0 commit comments

Comments
 (0)