Skip to content

Commit

Permalink
[LeetCode] Add January 06.
Browse files Browse the repository at this point in the history
  • Loading branch information
pin3da authored Jan 6, 2021
1 parent ac8e7bb commit ca1de7b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions solved/LeetCode/Challenges/2020/January/06.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
fun findKthPositive(arr: IntArray, k: Int): Int {
var missing = 0
var cur = 0
for (i in 1..(arr.size + k)) {
if (cur < arr.size && arr[cur] == i) {
cur++
} else {
missing++
}
if (missing == k) {
return i
}
}
error("Answer not found")
}
}

0 comments on commit ca1de7b

Please sign in to comment.