File tree 2 files changed +24
-0
lines changed
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 149
149
1389|[ Create Target Array in the Given Order] ( ./1389-create-target-array-in-the-given-order.js ) |Easy|
150
150
1408|[ String Matching in an Array] ( ./1408-string-matching-in-an-array.js ) |Easy|
151
151
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|
152
153
1472|[ Design Browser History] ( ./1472-design-browser-history.js ) |Medium|
153
154
1598|[ Crawler Log Folder] ( ./1598-crawler-log-folder.js ) |Easy|
154
155
1880|[ Check if Word Equals Summation of Two Words] ( ./1880-check-if-word-equals-summation-of-two-words.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments