Re: [闲聊] 每日LeetCode

楼主: Rushia (みけねこ的鼻屎)   2023-03-06 22:59:31
1539. Kth Missing Positive Number
给你一个已经排序且严格递增的整数阵列和一个数字k,返回第k个丢失的整数,这个整数
范围为1~N,且不包含阵列已经有的数字。
Example:
Input: arr = [2,3,4,7,11], k = 5
Output: 9
Explanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The
5th missing positive integer is 9.
法一 暴力
思路:
1.遍历阵列,如果阵列里面没有小于k的数,直接返回k
2.如果阵列里面有小于k的数字,k递增
3.返回k
Java Code:
作者: idiont (supertroller)   2023-03-06 23:13:00
大师
作者: NTHUlagka (拉卡)   2023-03-07 01:32:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com