Skip to content

Commit f7aecd1

Browse files
committed
Add solution #1437
1 parent a55b8d1 commit f7aecd1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
1389|[Create Target Array in the Given Order](./1389-create-target-array-in-the-given-order.js)|Easy|
150150
1408|[String Matching in an Array](./1408-string-matching-in-an-array.js)|Easy|
151151
1436|[Destination City](./1436-destination-city.js)|Easy|
152+
1437|[Check If All 1's Are at Least Length K Places Away](./1437-check-if-all-1s-are-at-least-length-k-places-away.js)|Easy|
152153
1472|[Design Browser History](./1472-design-browser-history.js)|Medium|
153154
1598|[Crawler Log Folder](./1598-crawler-log-folder.js)|Easy|
154155
1880|[Check if Word Equals Summation of Two Words](./1880-check-if-word-equals-summation-of-two-words.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 1437. Check If All 1's Are at Least Length K Places Away
3+
* https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away/
4+
* Difficulty: Easy
5+
*
6+
* Given an array nums of 0s and 1s and an integer k, return True if all 1's are at
7+
* least k places away from each other, otherwise return False.
8+
*/
9+
10+
/**
11+
* @param {number[]} nums
12+
* @param {number} k
13+
* @return {boolean}
14+
*/
15+
var kLengthApart = function(nums, k) {
16+
let offset = k;
17+
for (const num of nums) {
18+
if (num === 0) { offset++; continue; }
19+
if (offset < k) return false;
20+
offset = 0;
21+
}
22+
return true;
23+
};

0 commit comments

Comments
 (0)