最长上升连续子序列 给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列。(最长上升连续子序列可以定义为从右到左或从左到右的序列。)
Code
def count(self,A,aa):
res=0
dp = [[0] for i in range(aa)]
for i in range(0,aa,1):
dp[i]=1
if i>0 and A[i-1]<A[i]:
dp[i]=dp[i-1]+1
if dp[i]>res:
res=dp[i]
return res
def longestIncreasingContinuousSubsequence(self, A):
# write your code here
aa=len(A)
i,j=0,aa-1
if aa==0:
return 0
res1=self.count(A,aa)
while i<j:
t=A[i]
A[i]=A[j]
A[j]=t
i=i+1
j=j-1
res2=self.count(A,aa)
res=res1
if res2>res1:
res=res2
return res
397. 最长上升连续子序列最长上升连续子序列给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列。(最长上升连续子序列可以定义为从右到左或从左到右的序列。)Codedef count(self,A,aa): res=0 dp = [[0] for i in range(aa)] for i in range(0,aa,1): dp[i]=1 if i>0 and