遇见YY

导航

 

题目描述:给定一个无序的整数数组,找到其中最长上升子序列的长度。

示例:

输入: [10,9,2,5,3,7,101,18]
输出: 4
解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4。
说明:可能会有多种最长上升子序列的组合,你只需要输出对应的长度即可。

 

public class Out {
    public static void main(String[] args) {
       
    }



    public static int help(int[] nums) {
        if(nums.length == 0) return 0;
        int[] dp = new int[nums.length];
        dp[0] = 1;
        int Max = 1;
        for (int i = 1; i < nums.length; i++) {
            dp[i] = 1;
            for (int j = i - 1; j > -1; j--) {
                if (nums[i] > nums[j]) {
                    dp[i] = Math.max(dp[i],dp[j] + 1);
                }
            }
            Max = Math.max(Max,dp[i]);
        }
        return Max;
    }


}

 

posted on 2020-08-30 21:12  一骑红尘妃子笑!  阅读(255)  评论(0编辑  收藏  举报