mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-12 18:08:38 +08:00
1437
This commit is contained in:
26
25/11/1437.cpp
Normal file
26
25/11/1437.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user