leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 21e4ac374793d462a54ff7ee42a7d784f6d53476
parent eda9eb59b892f728e009d7c85b1246e308cc0025
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Mon, 20 Mar 2023 23:03:18 +0100

Daily Problem

Diffstat:
AProblems/0605.cpp | 18++++++++++++++++++
MREADME.md | 1+
2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/Problems/0605.cpp b/Problems/0605.cpp @@ -0,0 +1,18 @@ +class Solution { +public: + bool canPlaceFlowers(vector<int> &flowerbed, int n) { + int count = 1; + flowerbed.push_back(0); + flowerbed.push_back(1); + for (int crnt : flowerbed) { + if (!crnt) + count++; + else { + if (count >= 3) n -= (count - 3) / 2 + 1; + if (n <= 0) return true; + count = 0; + } + } + return false; + } +}; diff --git a/README.md b/README.md @@ -287,6 +287,7 @@ for solving problems. | 0583 | Medium | [Delete Operation for Two Strings](Problems/0583.cpp) | | 0589 | Easy | [N-ary Tree Preorder Traversal](Problems/0589.cpp) | | 0590 | Easy | [N-ary Tree Postorder Traversal](Problems/0590.cpp) | +| 0605 | Easy | [Can Place Flowers](Problems/0605.cpp) | | 0606 | Easy | [Construct String from Binary Tree ](Problems/0606.cpp) | | 0617 | Easy | [Merge Two Binary Trees](Problems/0617.cpp) | | 0621 | Medium | [Task Scheduler](Problems/0621.cpp) |