Skip to content

Commit d25d0f2

Browse files
authored
Update kth-missing-positive-number.py
1 parent df59ae4 commit d25d0f2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Python/kth-missing-positive-number.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ def findKthPositive(self, arr, k):
99
:rtype: int
1010
"""
1111
def check(arr, k, x):
12-
return arr[x]-(x+1) >= k
12+
return arr[x]-(x+1) < k
1313

1414
left, right = 0, len(arr)-1
1515
while left <= right:
1616
mid = left + (right-left)//2
17-
if check(arr, k, mid):
17+
if not check(arr, k, mid):
1818
right = mid-1
1919
else:
2020
left = mid+1
21-
return left+k # arr[left-1] + (k-(arr[left-1]-((left-1)+1))) if left else k
21+
return right+1+k # arr[right] + (k-(arr[right]-(right+1))) if right >= 0 else k

0 commit comments

Comments
 (0)