Check If All 1's Are at Least Length K Places Away Solutions in C++Number 1437Difficulty MediumAcceptance 63.1%Link LeetCodeOther languages —SolutionsC++ solution by liuyubobobo/Play-Leetcode/// Source : https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away//// Author : liuyubobobo/// Time : 2020-05-02 #include <iostream>#include <vector> using namespace std; /// Linear Scan/// Time Complexity: O(n)/// Space Complexity: O(1)class Solution {public: bool kLengthApart(vector<int>& nums, int k) { for(int start = -1, i = 0; i < nums.size(); i ++) if(nums[i] == 1){ if(start >= 0 && i - start - 1 < k) return false; start = i; } return true; }}; int main() { return 0;}/// Source : https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away/ /// Author : liuyubobobo /// Time : 2020-05-02 #include <iostream> #include <vector> using namespace std; /// Linear Scan /// Time Complexity: O(n) /// Space Complexity: O(1) class Solution { public: bool kLengthApart(vector<int>& nums, int k) { for(int start = -1, i = 0; i < nums.size(); i ++) if(nums[i] == 1){ if(start >= 0 && i - start - 1 < k) return false; start = i; } return true; } }; int main() { return 0; }