From 5c0972d75c514a73d2b22f271cdee9f0c166b1bc Mon Sep 17 00:00:00 2001 From: Tushar Tanaji Kurade Date: Wed, 29 Oct 2025 23:54:48 +0530 Subject: [PATCH] Implement canPlaceFlowers function in C++ --- canPlaceFlowers_shadowkakashi.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 canPlaceFlowers_shadowkakashi.cpp diff --git a/canPlaceFlowers_shadowkakashi.cpp b/canPlaceFlowers_shadowkakashi.cpp new file mode 100644 index 0000000..de88194 --- /dev/null +++ b/canPlaceFlowers_shadowkakashi.cpp @@ -0,0 +1,16 @@ +class Solution { +public: + bool canPlaceFlowers(vector& flowerbed, int n) { + for (int i = 0; i < flowerbed.size() && n > 0; ++i) { + if (flowerbed[i] == 0) { + bool left = (i == 0) || (flowerbed[i-1] == 0); + bool right = (i == flowerbed.size()-1) || (flowerbed[i+1] == 0); + if (left && right) { + flowerbed[i] = 1; + --n; + } + } + } + return n == 0; + } +};