Longest Increasing Continuous Subsequence
Source
Give an integer array,find the longest increasing continuous subsequence in this array.
An increasing continuous subsequence:
Can be from right to left or from left to right.
Indices of the integers in the subsequence should be continuous.
Example
For [5, 4, 2, 1, 3], the LICS is [5, 4, 2, 1], return 4.
For [5, 1, 2, 3, 4], the LICS is [1, 2, 3, 4], return 4.
Note
O(n) time and O(1) extra space.
Python
class Solution:
def longestIncreasingContinuousSubsequence(self, A):
if A is None or len(A)==0:
return 0
lics=1
maxLics=1
pre = A[0]
for i in range(1, len(A)):
if pre <A[i]:
lics +=1
else:
lics=1
maxLics = max(maxLics, lics)
pre = A[i]
lics=1
pre=A[0]
for i in range(1, len(A)):
if pre>A[i]:
lics+=1
else:
lics=1
maxLics = max(maxLics, lics)
pre = A[i]
return maxLics