力扣300.最长递增子序列(python版本)——DP

力扣300.最长递增子序列(python版本)——DP,第1张

# 题目
# https://leetcode.cn/problems/longest-increasing-subsequence/
# 参考链接
# https://blog.csdn.net/anan15151529/article/details/118162225
# 题解
# https://leetcode.cn/problems/longest-increasing-subsequence/solution/zui-chang-shang-sheng-zi-xu-lie-dong-tai-gui-hua-2/
class Solution(object):
    def lengthOfLIS(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        # if not nums:
        #     return 0
        n = len(nums)
        dp = [1 for _ in range(n)]
        for i in range(n):
            for j in range(i):
                if nums[i] > nums[j]:
                    dp[i] = max(dp[i], dp[j]+1)
        return max(dp)

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/904870.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-15
下一篇2022-05-15

发表评论

登录后才能评论

评论列表(0条)

    保存