Leecode no.300 最长递增子序列

package leecode;

/**
* 最长递增子序列
* 给你一个整数数组 nums ,找到其中最长严格递增子序列的长度。
*
* 子序列是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。例如,[3,6,2,7] 是数组 [0,3,1,6,2,2,7] 的子序列
*
*
* @author Tang
* @date 20210907
*/
public class MaxLengthChild {

int[] tables;

public int execute(int[] nums) {
//构建备忘录
tables = new int[nums.length];

//倒序数组
for(int i = nums.length - 1; i >= 0; i--){
if(i == nums.length - 1) {
tables[i] = 1;
}

int maxValue = 0;
for(int j = i+1; j < nums.length; j++) {
if(nums[i] < nums[j]) {
maxValue = Math.max(tables[j], maxValue);
}
}
tables[i] = maxValue + 1;
}

int max = 0;
for (int value : tables) {
if(value > max) {
max = value;
}
}
return max;
}


public static void main(String[] args) {
int[] nums = {0,1,0,3,2,3};
System.out.println(new MaxLengthChild().execute(nums));

}
}
原文地址:https://www.cnblogs.com/ttaall/p/14831422.html