Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bc03169

Browse files
author
Sandy
authored
Merge pull request #224 from openset/develop
Add: Longest Continuous Increasing Subsequence
2 parents 163783e + 4d538bf commit bc03169

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)

AltStyle によって変換されたページ (->オリジナル) /