public class Solution {
/**
* @param A an array of Integer
* @return an integer
*/
public int longestIncreasingContinuousSubsequence(int[] A) {
int n=A.length;
int count1=0,count2=0;
int s1=0,s2=0;
for(int i=0;i<n;i++){
count1=1;
for(int j=i+1;j<n;j++){
if(A[j]>A[j-1]){
count1++;
}else{
break;
}
}
if(count1>s1){
s1=count1;
}
}
for(int i=0;i<n;i++){
count2=1;
for(int j=i+1;j<n;j++){
if(A[j]<A[j-1]){
count2++;
}else{
break;
}
}
if(count2>s2){
s2=count2;
}
}
if(s1>s2){
return s1;
}else{
return s2;
}
}
}
需要注意的问题:
1.for(int i=0;i<n;i++){
count1=1;
for(int j=i+1;j<n;j++){
if(A[j]>A[j-1]){
count1++;
}else{
break;
}
}
注意嵌套中j的初始取值应该为i+1;
lintcode397最长上升连续子序列(动态规划easy)
最新推荐文章于 2021-05-12 08:19:07 发布