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