题解 | #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))

全部评论

相关推荐

大叔叔1:你把自己说的话打码,所以你想表达什么
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务