Skip to content

Commit 4d538bf

Browse files
committed
Add: Longest Continuous Increasing Subsequence
1 parent 84e7daa commit 4d538bf

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
11
package longest_continuous_increasing_subsequence
2+
3+
func findLengthOfLCIS(nums []int) int {
4+
max, cur := 0, 1
5+
for i, v := range nums {
6+
if i >= 1 && v > nums[i-1] {
7+
cur++
8+
} else {
9+
cur = 1
10+
}
11+
if cur > max {
12+
max = cur
13+
}
14+
}
15+
return max
16+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
11
package longest_continuous_increasing_subsequence
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input []int
7+
expected int
8+
}
9+
10+
func TestFindLengthOfLCIS(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: []int{1, 3, 5, 4, 7},
14+
expected: 3,
15+
},
16+
{
17+
input: []int{2, 2, 2, 2, 2},
18+
expected: 1,
19+
},
20+
{
21+
input: []int{},
22+
expected: 0,
23+
},
24+
{
25+
input: []int{1, 3, 5, 7},
26+
expected: 4,
27+
},
28+
}
29+
for _, tc := range tests {
30+
output := findLengthOfLCIS(tc.input)
31+
if output != tc.expected {
32+
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)