lintcode:最长上升连续子序列
程序员文章站
2022-03-24 17:38:26
...
class Solution:
"""
@param: A: An array of Integer
@return: an integer
"""
def longestIncreasingContinuousSubsequence(self, A):
# write your code here
if len(A) < 3:
return len(A)
# 一直升序排列
flag, count_1 = 1, 0
for i in range(1, len(A)):
if A[i] > A[i - 1]:
flag += 1
else:
count_1 = max(count_1, flag)
flag = 1
count_1 = max(count_1, flag)
# 一直降序排列
flag, count_2 = 1, 0
for j in range(1, len(A)):
if A[j] < A[j - 1]:
flag += 1
count_2 = max(count_2, flag)
else:
count_2 = max(count_2, flag)
flag = 1
count_2 = max(count_2, flag)
return max(count_1, count_2)