Skip to content

Commit

Permalink
Time: 21 ms (79.23%), Space: 20.3 MB (69.44%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
ArbitCode committed Sep 2, 2022
1 parent 31368fe commit 8ace4bc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 605-can-place-flowers/605-can-place-flowers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public:
bool canPlaceFlowers(vector<int>& flowerbed, int n) {
int count = 0;
for(int i = 0; i < flowerbed.size(); i++){
if(flowerbed[i] == 0){
//left and right free ho
bool isLeftFree = (i == 0) || flowerbed[i - 1] == 0;
bool isRightFree = (i == flowerbed.size() - 1) || flowerbed[i + 1] == 0;
if(isLeftFree && isRightFree) count++, flowerbed[i] = 1;
}
}
return count >= n;
}
};

0 comments on commit 8ace4bc

Please sign in to comment.