package com.ohere;
public class LongestIncreasingSubSet {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] test = {1,7,3,5,9,4,8,9,10};
longestString(test);
}
public static void longestString(int [] str){
int [] maxLength = new int[str.length];
maxLength[0] = 1;
for (int i = 1; i < str.length; i++){
int tempLen = 0;
for (int j = 0; j < i;j++){
if (str[j] < str[i]){
tempLen = Math.max(tempLen, maxLength[j]);
}
}
maxLength[i] = tempLen + 1;
}
int result = 0;
for (int x: maxLength){
result = Math.max(result, x);
}
System.out.println(result);
}
}
动规基础,最长上升子序列
最新推荐文章于 2020-04-08 17:31:36 发布