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; } }

 
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号