Advertisement

dynamic programming|longest increasing subsequence length

阅读量:

题目:300.最长上升子序列

针对一个未排序的整数序列,确定其中最长递增子序列的长度。

示例:

输入: [10,9,2,5,3,7,101,18]
输出: 4
解释: 在该序列中,最长递增子序列为 [2,3,7,101],其包含的元素数量为4。

在这里插入图片描述

一:利用递归实现最长上升子序列

复制代码
    import time
    import random
    
    #####      init 300.最长上升子序列  ########
    def lts(input):
    result = 0
    for index in range(len(input)):
        result = max(result,f(input,index))
    
    return result
    
    def f(input,index):
    res = 1
    for j in range(len(input)):
    
        if j< index and input[j]< i

全部评论 (0)

还没有任何评论哟~