From ca1de7bff4c296351f3cdbd153cca98c71fc8138 Mon Sep 17 00:00:00 2001 From: Manuel Pineda Date: Wed, 6 Jan 2021 17:01:39 +0100 Subject: [PATCH] [LeetCode] Add January 06. --- solved/LeetCode/Challenges/2020/January/06.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 solved/LeetCode/Challenges/2020/January/06.kt diff --git a/solved/LeetCode/Challenges/2020/January/06.kt b/solved/LeetCode/Challenges/2020/January/06.kt new file mode 100644 index 00000000..e3928dbc --- /dev/null +++ b/solved/LeetCode/Challenges/2020/January/06.kt @@ -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") + } +}