File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,353 LeetCode solutions in JavaScript
1
+ # 1,354 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1175
1175
1535|[ Find the Winner of an Array Game] ( ./solutions/1535-find-the-winner-of-an-array-game.js ) |Medium|
1176
1176
1536|[ Minimum Swaps to Arrange a Binary Grid] ( ./solutions/1536-minimum-swaps-to-arrange-a-binary-grid.js ) |Medium|
1177
1177
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|
1178
1179
1550|[ Three Consecutive Odds] ( ./solutions/1550-three-consecutive-odds.js ) |Easy|
1179
1180
1551|[ Minimum Operations to Make Array Equal] ( ./solutions/1551-minimum-operations-to-make-array-equal.js ) |Medium|
1180
1181
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|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments