mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-12 18:08:38 +08:00
15 lines
354 B
Java
15 lines
354 B
Java
class Solution {
|
|
public boolean kLengthApart(int[] nums, int k) {
|
|
int last = -k - 1;
|
|
for (int i = 0; i < nums.length; i++) {
|
|
if (nums[i] != 1) {
|
|
continue;
|
|
}
|
|
if (i - last <= k) {
|
|
return false;
|
|
}
|
|
last = i;
|
|
}
|
|
return true;
|
|
}
|
|
} |