Easy
将现有数组构造成哈希表,然后逐个遍历,直到数出不在哈希表中的第k
个数
以上,AC!
python3
class Solution:
def findKthPositive(self, arr: List[int], k: int) -> int:
s = set(arr)
res = 0
l = 0
for x in range(1,10000):
if l == k:
return res
if x not in s:
res = x
l += 1