1437. Check If All 1's Are at Least Length K Places Away Easy
1/**
2 * [1437] Check If All 1's Are at Least Length K Places Away
3 *
4 * Given an binary array nums and an integer k, return true if all 1's are at least k places away from each other, otherwise return false.
5 *
6 * Example 1:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2020/04/15/sample_1_1791.png" style="width: 428px; height: 181px;" />
8 * Input: nums = [1,0,0,0,1,0,0,1], k = 2
9 * Output: true
10 * Explanation: Each of the 1s are at least 2 places away from each other.
11 *
12 * Example 2:
13 * <img alt="" src="https://assets.leetcode.com/uploads/2020/04/15/sample_2_1791.png" style="width: 320px; height: 173px;" />
14 * Input: nums = [1,0,0,1,0,1], k = 2
15 * Output: false
16 * Explanation: The second 1 and third 1 are only one apart from each other.
17 *
18 *
19 * Constraints:
20 *
21 * 1 <= nums.length <= 10^5
22 * 0 <= k <= nums.length
23 * nums[i] is 0 or 1
24 *
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away/
29// discuss: https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34 pub fn k_length_apart(nums: Vec<i32>, k: i32) -> bool {
35 false
36 }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_1437() {
47 }
48}
49
Back
© 2025 bowen.ge All Rights Reserved.