C++
双向递推
空间O(1)
时间O(n)
1 class Solution { 2 public: 3 /** 4 * @param A an array of Integer 5 * @return an integer 6 */ 7 int longestIncreasingContinuousSubsequence(vector<int>& A) { 8 // Write your code here 9 int n = A.size(); 10 if ( n == 1 || n == 0) { 11 return n; 12 } 13 int dp; 14 int ans = 1; 15 //>>>>>>> 16 dp = 1; 17 for (int i=1; i<=n; ++i) { 18 dp = A[i]>=A[i-1]?dp+1:1; 19 ans = max(dp, ans); 20 } 21 //<<<<<<< 22 dp = 1; 23 for (int i=n-2; i>=0; --i) { 24 dp = A[i]>=A[i+1]?dp+1:1; 25 ans = max(dp, ans); 26 } 27 return ans; 28 } 29 };
本文转自ZH奶酪博客园博客,原文链接:http://www.cnblogs.com/CheeseZH/p/5006811.html,如需转载请自行联系原作者