Leecode数据结构刷题记录第四天:300. 最长递增子序列(动态规划)

 

 ①:dp动态规划

public class Solution {
    public int LengthOfLIS(int[] nums) {
int[] dp = new int[nums.Length];
            for (int i = 0; i < nums.Length; i++) 
            {
                dp[i] = 1;
            }
            for (int i = 0; i < nums.Length; i++) 
            {
                for (int j = 0; j < i; j++) 
                {
                    if (nums[i] > nums[j]) 
                    {
                        dp[i] = Math.Max(dp[i], 1 + dp[j]);
                    }
                }
            }
            int res = 0;
            for (int i = 0; i < dp.Length; i++) 
            {
                res = Math.Max(res, dp[i]);

            }
            return res;
    }
}

 附上详细解析:动态规划设计:最长递增子序列 :: labuladong的算法小抄 (gitee.io)

posted @ 2021-11-12 16:09  奕心1999  阅读(14)  评论(0)    收藏  举报