Advertisement

最长递增子序列(LIS):从一维扩展至三维空间

阅读量:

文章结构概览

  • 1 【1维

1 【1维】最长递增子序列

1.最长递增子序列长度求解

300. 最长递增子序列

1.1.1 n^2 时间复杂度

复制代码
    class Solution:
    def lengthOfLIS(self, nums: List[int]) -> int:
        n = len(nums)
        dp = [1] * n
        ans = 0
        for i in range(1, n):
            for j in range(i):
                if nums[i] > nums[j]:
                    dp[i] = max(dp[i], dp[j] + 1)
                    ans = max(ans, dp[i])
        return max(dp)
    
    
    
      
      
      
      
      
      
      
      
      

全部评论 (0)

还没有任何评论哟~