首页 > 其他 > 详细

最长上升子序列

时间:2018-09-30 13:30:04      阅读:165      评论:0      收藏:0      [点我收藏+]
# 最长上升子序列
class Solution:
    """
    @param nums: An integer array
    @return: The length of LIS (longest increasing sequence)
    """

    def longest_increasing_sequence(self, nums):
        # write your code here
        dp = [1 for i in range(len(nums))]
        print(dp)
        max_result = 0
        for i in range(1, len(nums)):
            for j in range(0, i):
                if (nums[j] < nums[i]):
                    dp[i] = max(dp[i], dp[j] + 1)
            max_result = max(dp[i], max_result)
        return max_result


s = Solution()
print(s.longest_increasing_sequence([5, 4, 1, 2, 3, 4]))

 

最长上升子序列

原文:https://www.cnblogs.com/xiao-xue-di/p/9729149.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!