题解 | #Redraiment的走法# 贪心 + 二分法

Redraiment的走法

https://www.nowcoder.com/practice/24e6243b9f0446b081b1d6d32f2aa3aa

n = int(input())
nums = list(map(int, input().split()))
#贪心
res = []

for num in nums:
    if not res or res[-1] < num:
        res.append(num)
    #大于 则替换
    l,r = 0,len(res)#找到要替换的数
    while l < r:
        mid = (l+r) // 2
        if res[mid] >= num:
            r = mid
        else:l = mid + 1
    if r == len(res):res.append(num)
    else:res[r] = num
print(len(res))

全部评论

相关推荐

见见123:简历没有啥问题,是这个社会有问题。因为你刚毕业,没有工作经历,现在企业都不要没有工作经历的。社会病了。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 15:58
投个小米提前批试试水,先投一个岗位看看形势,不行就再沉淀一下投第二个岗位,莫辜负
Java抽象带篮子:我嘞个骚刚,已经开始研发6g了吗
投递小米集团等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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