From e4e678ea943e41a17bdd82e469df365d0bd43a37 Mon Sep 17 00:00:00 2001 From: Manuel Pineda Date: Mon, 25 Jan 2021 19:51:08 +0100 Subject: [PATCH] [LeetCode] Add January 25. --- solved/LeetCode/Challenges/2020/January/25.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 solved/LeetCode/Challenges/2020/January/25.kt diff --git a/solved/LeetCode/Challenges/2020/January/25.kt b/solved/LeetCode/Challenges/2020/January/25.kt new file mode 100644 index 00000000..5e14749d --- /dev/null +++ b/solved/LeetCode/Challenges/2020/January/25.kt @@ -0,0 +1,16 @@ +class Solution { + fun kLengthApart(nums: IntArray, k: Int): Boolean { + var posOnes = mutableListOf() + for ((i, v) in nums.withIndex()) { + if (v == 1) { + posOnes.add(i) + } + } + for (i in 1 until posOnes.size) { + if (posOnes[i] - posOnes[i - 1] <= k) { + return false + } + } + return true + } +}