[LintCode] Longest Increasing Continuous subsequence
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
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