LeetCode 1437. Check If All 1's Are at Least Length K Places Away Posted on 2021-01-25 Edited on 2021-01-26 In LeetCode Notes 题目原题在此 解析这题还用解析么? 是有人不会呢, 还是会有公司出这种面试题. 这个页面肯定没人看所以就写点儿垃圾话好了. 代码c++1234567891011121314class Solution {public: bool kLengthApart(vector<int>& nums, int k) { int i = -1, n = nums.size(); for (int j = 0; j < n; ++j) { if (nums[j] == 1) { if (i != -1 && j - i - 1 < k) return false; i = j; } } return true; }};