Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit ebb8cb2

Browse files
aQuaaQua
aQua
authored and
aQua
committed
674 added
1 parent 02fc1ad commit ebb8cb2

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# [674. Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence/)
2+
3+
## 题目
4+
5+
Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray).
6+
7+
Example 1:
8+
9+
```text
10+
Input: [1,3,5,4,7]
11+
Output: 3
12+
Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3.
13+
Even though [1,3,5,7] is also an increasing subsequence, it's not a continuous one where 5 and 7 are separated by 4.
14+
```
15+
16+
Example 2:
17+
18+
```text
19+
Input: [2,2,2,2,2]
20+
Output: 1
21+
Explanation: The longest continuous increasing subsequence is [2], its length is 1.
22+
```
23+
24+
Note: Length of the array will not exceed 10,000.
25+
26+
## 解题思路
27+
28+
见程序注释
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package Problem0674
2+
3+
func findLengthOfLCIS(nums []int) int {
4+
res := 0
5+
6+
return res
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package Problem0674
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
// tcs is testcase slice
11+
var tcs = []struct {
12+
nums []int
13+
ans int
14+
}{
15+
16+
{
17+
[]int{1, 3, 5, 4, 7},
18+
3,
19+
},
20+
21+
{
22+
[]int{2, 2, 2, 2, 2},
23+
1,
24+
},
25+
26+
// 可以有多个 testcase
27+
}
28+
29+
func Test_fn(t *testing.T) {
30+
ast := assert.New(t)
31+
32+
for _, tc := range tcs {
33+
fmt.Printf("~~%v~~\n", tc)
34+
ast.Equal(tc.ans, findLengthOfLCIS(tc.nums), "输入:%v", tc)
35+
}
36+
}
37+
38+
func Benchmark_fn(b *testing.B) {
39+
for i := 0; i < b.N; i++ {
40+
for _, tc := range tcs {
41+
findLengthOfLCIS(tc.nums)
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)