diff --git a/Easy/FlowerBed_problem/flowerbed.cpp b/Easy/FlowerBed_problem/flowerbed.cpp new file mode 100644 index 0000000..959f5c1 --- /dev/null +++ b/Easy/FlowerBed_problem/flowerbed.cpp @@ -0,0 +1,24 @@ +class Solution { +public: + bool canPlaceFlowers(vector& 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 && leftEmpty == true && currentEmpty == true) + { + flowerbed[i] = 1; y++; + } + } + } + + if (n <= y) return true; + else return false; + } +}; \ No newline at end of file