[LintCode] Longest Increasing Continuous subsequence
public int longestIncreasingContinuousSubsequence(int[] A) { // Write your code here if(A == null || A.length == 0) return 0; if(A.length == 1)// corn case; return 1; int count = 1; int max = 0; for(int i = 1; i < A.length; i++) { if(A[i] > A[i-1]){ count++; }else{ count = 1; } max = Math.max(max,count); } count = 1; for(int i = A.length - 1; i > 0; i--) { if(A[i] < A[i-1]){ count++; }else{ count = 1; } max = Math.max(max,count); } return max; }
Leave A Comment