Skip to content

Commit

Permalink
[LeetCode] Add January 25.
Browse files Browse the repository at this point in the history
  • Loading branch information
pin3da authored Jan 25, 2021
1 parent 08ac8bd commit e4e678e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions solved/LeetCode/Challenges/2020/January/25.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
fun kLengthApart(nums: IntArray, k: Int): Boolean {
var posOnes = mutableListOf<Int>()
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
}
}

0 comments on commit e4e678e

Please sign in to comment.