题解 | #查找第K小数#

查找第K小数

https://www.nowcoder.com/practice/204dfa6fcbc8478f993d23f693189ffd

n = int(input())
num = list(map(int, input().split(" ")))
x = int(input()) - 1
ct = 0
num.sort()
if n > 1:
    for i in range(n - 1):
        if num[i] < num[i + 1]:
            ct += 1
            ans = num[i + 1]
        if ct == x:
            break
else:
    ans = num[0]
print(ans)

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务