最长上升子序列

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

 

posted @ 2018-09-30 13:13  小学弟-  阅读(102)  评论(0编辑  收藏  举报