mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-13 02:38:37 +08:00
26 lines
414 B
C++
26 lines
414 B
C++
#include <vector>
|
|
|
|
bool kLengthApart(std::vector<int> &nums, int k) {
|
|
int count = 0;
|
|
bool start = false;
|
|
|
|
for (int i = 0; i < nums.size(); ++i) {
|
|
if (!start) {
|
|
if (nums[i] == 1) {
|
|
start = true;
|
|
}
|
|
continue;
|
|
}
|
|
if (nums[i] == 0) {
|
|
count++;
|
|
}
|
|
if (nums[i] == 1) {
|
|
if (count < k) {
|
|
return false;
|
|
}
|
|
count = 0;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
} |