mirror of
https://github.com/mudabbir-ahmad/Leet-Code-prog.git
synced 2026-10-08 10:40:20 +00:00
24 lines
690 B
C++
24 lines
690 B
C++
class Solution {
|
|
public:
|
|
bool canPlaceFlowers(vector<int>& flowerbed, int n) {
|
|
|
|
int y = 0;
|
|
for (int x = 0; x < n; x++)
|
|
{
|
|
for (int i = 0; i < (flowerbed.size()); i++)
|
|
{
|
|
bool leftEmpty = (i == 0) || (flowerbed[i-1] != 1);
|
|
bool rightEmpty = (i == flowerbed.size()-1) || (flowerbed[i+1] != 1);
|
|
bool currentEmpty = (flowerbed[i] != 1);
|
|
|
|
if (leftEmpty == true && rightEmpty == true && currentEmpty == true)
|
|
{
|
|
flowerbed[i] = 1; y++;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (n <= y) return true;
|
|
else return false;
|
|
}
|
|
}; |