leetcode

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

0605.cpp (457B)


      1 class Solution {
      2   public:
      3     bool canPlaceFlowers(vector<int> &flowerbed, int n) {
      4         int count = 1;
      5         flowerbed.push_back(0);
      6         flowerbed.push_back(1);
      7         for (int crnt : flowerbed) {
      8             if (!crnt)
      9                 count++;
     10             else {
     11                 if (count >= 3) n -= (count - 3) / 2 + 1;
     12                 if (n <= 0) return true;
     13                 count = 0;
     14             }
     15         }
     16         return false;
     17     }
     18 };