Skip to content

Commit 5a5201e

Browse files
authored
Create check-if-all-1s-are-at-least-length-k-places-away.py
1 parent 90d4fe7 commit 5a5201e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def kLengthApart(self, nums, k):
6+
"""
7+
:type nums: List[int]
8+
:type k: int
9+
:rtype: bool
10+
"""
11+
prev = -k-1
12+
for i in xrange(len(nums)):
13+
if not nums[i]:
14+
continue
15+
if i-prev <= k:
16+
return False
17+
prev = i
18+
return True

0 commit comments

Comments
 (0)