最长上升子序列(一)

image.png

思路:
1、用dp[i]表示到元素i结尾时,最长的子序列的长度
2、两层遍历,第一层遍历得到n个长度的子数组,第二层遍历相应子数组,j对应子数组遍历的位置,获取对应到元素i结尾时的最长递增序列长度 dp[i] = dp[j]+1;

public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 给定数组的最长严格上升子序列的长度。
     * @param arr int整型一维数组 给定的数组
     * @return int整型
     */
    public int LIS (int[] arr) {
        // write code here
        int length = arr.length;
        int [] dp = new int[length] ;
        int res = 0;
        for(int i = 1;i

你可能感兴趣的:(最长上升子序列(一))