码迷,mamicode.com
首页 > 其他好文 > 详细

最长上升子序列

时间:2018-09-30 14:43:11      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:ges   range   @param   sequence   seq   sel   序列   incr   integer   

# 最长上升子序列
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]))

 

最长上升子序列

标签:ges   range   @param   sequence   seq   sel   序列   incr   integer   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!