题解 | 最长上升子序列(一)贪心+二分 python

最长上升子序列(一)

https://www.nowcoder.com/practice/5f65ccbb025240bd8458eb6479c2612e

import bisect
import sys

l = int(input())
nums = list(map(int, input().split()))

res = [nums[0]]
for x in nums:
    if x > res[-1]:
        res.append(x)
        continue
    
    # linear search O(n)
    # for ind, y in enumerate(res):
    #     if x <= y:
    #         res[ind] = x
    #         break
    # bisearch O(logn)
    ind = bisect.bisect_left(res, x)
    res[ind] = x

print(len(res))

#python#
全部评论

相关推荐

码农索隆:有点耳熟,你们是我教过最差的一届
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 12:10
点赞 评论 收藏
分享
小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务