Give an integer array,find the longest increasing continuous subsequence in this array.
An increasing continuous subsequence:
- The Can is from the right-to-left or from the left-to-right.
- Indices of the integers in the subsequence should is continuous.
Example
[5, 4, 2, 1, 3]
for, the LICs [5, 4, 2, 1]
is, return 4
.
[5, 1, 2, 3, 4]
for, the LICs [1, 2, 3, 4]
is, return 4
.
Notice
O (n) time and O (1) extra space.
Public classSolution {/** * @paramA array of integers *@returnAn integer*/ Public intLongestincreasingcontinuoussubsequence (int[] A) {//Write Your code here if(A = =NULL|| A.length = = 0) return0; if(A.length = = 1) return1; intresult = 1; intCount = 1; for(inti = 1; i < a.length; i++){ if(A[i] > A[i-1]) Count++; ElseCount= 1; if(Count >result) Result=count; } Count= 1; for(inti = a.length-2; I >= 0; i--){ if(A[i] > a[i + 1]) Count++; ElseCount= 1; if(Count >result) Result=count; } returnresult; }}
Lintcode-easy-longest increasing continuous subsequence