Skip to content

Commit c01326c

Browse files
committedApr 18, 2025
Add solution #1539
1 parent 569da7d commit c01326c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,353 LeetCode solutions in JavaScript
1+
# 1,354 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1175,6 +1175,7 @@
11751175
1535|[Find the Winner of an Array Game](./solutions/1535-find-the-winner-of-an-array-game.js)|Medium|
11761176
1536|[Minimum Swaps to Arrange a Binary Grid](./solutions/1536-minimum-swaps-to-arrange-a-binary-grid.js)|Medium|
11771177
1537|[Get the Maximum Score](./solutions/1537-get-the-maximum-score.js)|Hard|
1178+
1539|[Kth Missing Positive Number](./solutions/1539-kth-missing-positive-number.js)|Easy|
11781179
1550|[Three Consecutive Odds](./solutions/1550-three-consecutive-odds.js)|Easy|
11791180
1551|[Minimum Operations to Make Array Equal](./solutions/1551-minimum-operations-to-make-array-equal.js)|Medium|
11801181
1566|[Detect Pattern of Length M Repeated K or More Times](./solutions/1566-detect-pattern-of-length-m-repeated-k-or-more-times.js)|Easy|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* 1539. Kth Missing Positive Number
3+
* https://leetcode.com/problems/kth-missing-positive-number/
4+
* Difficulty: Easy
5+
*
6+
* Given an array arr of positive integers sorted in a strictly increasing order, and an integer k.
7+
*
8+
* Return the kth positive integer that is missing from this array.
9+
*/
10+
11+
/**
12+
* @param {number[]} arr
13+
* @param {number} k
14+
* @return {number}
15+
*/
16+
var findKthPositive = function(arr, k) {
17+
let left = 0;
18+
let right = arr.length - 1;
19+
20+
while (left <= right) {
21+
const mid = Math.floor((left + right) / 2);
22+
const count = arr[mid] - mid - 1;
23+
24+
if (count < k) {
25+
left = mid + 1;
26+
} else {
27+
right = mid - 1;
28+
}
29+
}
30+
31+
return left + k;
32+
};

0 commit comments

Comments
 (0)
Please sign in to comment.