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

Commit e2ba356

Browse files
aQuaaQua
aQua
authored and
aQua
committed
673 added
1 parent d105224 commit e2ba356

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# [673. Number of Longest Increasing Subsequence](https://leetcode.com/problems/number-of-longest-increasing-subsequence/)
2+
3+
## 题目
4+
5+
Given an unsorted array of integers, find the number of longest increasing subsequence.
6+
7+
Example 1:
8+
9+
```text
10+
Input: [1,3,5,4,7]
11+
Output: 2
12+
Explanation: The two longest increasing subsequence are [1, 3, 4, 7] and [1, 3, 5, 7].
13+
```
14+
15+
Example 2:
16+
17+
```text
18+
Input: [2,2,2,2,2]
19+
Output: 5
20+
Explanation: The length of longest continuous increasing subsequence is 1, and there are 5 subsequences' length is 1, so output 5.
21+
```
22+
23+
Note: Length of the given array will be not exceed 2000 and the answer is guaranteed to be fit in 32-bit signed int.
24+
25+
## 解题思路
26+
27+
见程序注释
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package Problem0673
2+
3+
func findNumberOfLIS(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 Problem0673
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+
2,
19+
},
20+
21+
{
22+
[]int{2, 2, 2, 2, 2},
23+
5,
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, findNumberOfLIS(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+
findNumberOfLIS(tc.nums)
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)