leetcode-187周赛-5401-是否所有1都至少相隔k个元素

题目描述:

 

提交:O(N)

class Solution:
    def kLengthApart(self, nums: List[int], k: int) -> bool:
        c = k
        for i in nums:
            if i == 1:
                if c < k:
                    return False
                else:
                    c = 0
            else:
                c += 1
        return True

 

posted @ 2020-05-03 20:44  oldby  阅读(125)  评论(0编辑  收藏  举报