package me.wayne.leetcodetop100.dp;

import java.util.Arrays;

/**
 * 给定一个无序的整数数组，找到其中最长上升子序列的长度。
 * <p>
 * 输入: [10,9,2,5,3,7,101,18]
 * 输出: 4
 * 解释: 最长的上升子序列是 [2,3,7,101]，它的长度是 4。
 */
class LC300_LengthOfLIS {

    public int lengthOfLIS(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }

        //dp[i]的含义是以 num[i] 为结尾的最长递增子序列
        int[] dp = new int[nums.length];
        Arrays.fill(dp, 1);
        for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    dp[i] = Math.max(dp[j] + 1, dp[i]);
                }
            }
        }

        int max = 0;
        for (int value : dp) {
            max = Math.max(max, value);
        }
        return max;
    }
}
@@ -205,16 +205,70 @@
 fLIS %7B%0A%0A
+    /**%0A     * Longest Increasing Subsequence%0A     */%0A
     publ
@@ -532,24 +532,164 @@
 gth; i++) %7B%0A
+            //j %3E= 0 %E4%B8%94 %3C i%EF%BC%8C%E6%AF%8F%E8%BD%AE%E8%AE%A1%E7%AE%97dp%5Bi%5D%E6%97%B6%EF%BC%8C%E9%81%8D%E5%8E%86%5B0, i%7D%0A            //%E5%BD%93nums%5Bi%5D%3Enums%5Bj%5D%E6%97%B6%EF%BC%8C%E6%BB%A1%E8%B6%B3%E6%9D%A1%E4%BB%B6%EF%BC%8CLIS%E4%B8%BAdp%5Bj%5D + 1%0A            //%E5%BD%93nums%5Bi%5D%3C=nums%5Bj%5D%E6%97%B6%EF%BC%8C%E4%B8%8D%E6%BB%A1%E8%B6%B3%E6%9D%A1%E4%BB%B6%EF%BC%8C%E8%B7%B3%E8%BF%87%0A
             

refactor LC300_LengthOfLIS