Skip to content

Commit bbb3aa0

Browse files
committed
最长上升连续子序列
1 parent 58bb990 commit bbb3aa0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
3+
class Solution:
4+
# @param {int[]} A an array of Integer
5+
# @return {int} an integer
6+
def longestIncreasingContinuousSubsequence(self, A):
7+
# Write your code here
8+
len_a = len(A)
9+
if len_a <= 1:
10+
return len_a
11+
sign = 1 if A[0] < A[1] else -1
12+
i, seq_count, max_seq_count = 1, 1, 0
13+
while i < len_a:
14+
if sign > 0:
15+
if A[i] >= A[i - 1]:
16+
seq_count += 1
17+
else:
18+
if seq_count > max_seq_count:
19+
max_seq_count = seq_count
20+
seq_count = 2
21+
sign = -1
22+
else:
23+
if A[i] <= A[i - 1]:
24+
seq_count += 1
25+
else:
26+
if seq_count > max_seq_count:
27+
max_seq_count = seq_count
28+
seq_count = 2
29+
sign = 1
30+
i += 1
31+
return max_seq_count if max_seq_count >= seq_count else seq_count

0 commit comments

Comments
 (0)