Skip to content

Commit dcefa9e

Browse files
add 1437
1 parent c8a33d0 commit dcefa9e

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1437|[Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1437.java) | |Medium|Array|
1112
|1436|[Destination City](https://leetcode.com/problems/destination-city/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1436.java) | |Easy|String|
1213
|1432|[Max Difference You Can Get From Changing an Integer](https://leetcode.com/problems/max-difference-you-can-get-from-changing-an-integer/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1432.java) | |Medium|String|
1314
|1431|[Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1431.java) | |Easy|Array|
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _1437 {
7+
public static class Solution1 {
8+
public boolean kLengthApart(int[] nums, int k) {
9+
List<Integer> indexes = new ArrayList<>();
10+
for (int i = 0; i < nums.length; i++) {
11+
if (nums[i] == 1) {
12+
indexes.add(i);
13+
}
14+
}
15+
for (int i = 0; i < indexes.size() - 1; i++) {
16+
if (indexes.get(i + 1) - indexes.get(i) < k + 1) {
17+
return false;
18+
}
19+
}
20+
return true;
21+
}
22+
}
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1437;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static junit.framework.TestCase.assertEquals;
8+
9+
public class _1437Test {
10+
private static _1437.Solution1 solution1;
11+
private static int[] nums;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _1437.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
nums = new int[]{1, 0, 0, 0, 1, 0, 0, 1};
21+
assertEquals(true, solution1.kLengthApart(nums, 2));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)