mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
21 lines
273 B
Go
21 lines
273 B
Go
package leetcode
|
|
|
|
func findKthPositive(arr []int, k int) int {
|
|
positive, index := 1, 0
|
|
for index < len(arr) {
|
|
if arr[index] != positive {
|
|
k--
|
|
} else {
|
|
index++
|
|
}
|
|
if k == 0 {
|
|
break
|
|
}
|
|
positive++
|
|
}
|
|
if k != 0 {
|
|
positive += k - 1
|
|
}
|
|
return positive
|
|
}
|