Class Solution
java.lang.Object
g1401_1500.s1437_check_if_all_1s_are_at_least_length_k_places_away.Solution
1437 - Check If All 1’s Are at Least Length K Places Away.<p>Easy</p>
<p>Given an binary array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if all</em> <code>1</code><em>’s are at least</em> <code>k</code> <em>places away from each other, otherwise return</em> <code>false</code>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/04/15/sample_1_1791.png" alt="" /></p>
<p><strong>Input:</strong> nums = [1,0,0,0,1,0,0,1], k = 2</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> Each of the 1s are at least 2 places away from each other.</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/04/15/sample_2_1791.png" alt="" /></p>
<p><strong>Input:</strong> nums = [1,0,0,1,0,1], k = 2</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> The second 1 and third 1 are only one apart from each other.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>0 <= k <= nums.length</code></li>
<li><code>nums[i]</code> is <code>0</code> or <code>1</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
kLengthApart
public boolean kLengthApart(int[] nums, int k)
-