Skip to content

Commit b1a779e

Browse files
authored
Create 1437. Check If All 1's Are at Least Length K Places Away (#935)
2 parents 7e5c715 + d1ca172 commit b1a779e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
bool kLengthApart(vector<int>& nums, int k) {
4+
int prev = -1;
5+
6+
for(int i = 0; i < nums.size(); i++){
7+
if(nums[i] == 1){
8+
if(prev != -1 && i - prev - 1 < k)
9+
return false;
10+
prev = i;
11+
}
12+
}
13+
return true;
14+
}
15+
};

0 commit comments

Comments
 (0)