leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0605.cpp (457B)
0 class Solution { 1 public: 2 bool canPlaceFlowers(vector<int> &flowerbed, int n) { 3 int count = 1; 4 flowerbed.push_back(0); 5 flowerbed.push_back(1); 6 for (int crnt : flowerbed) { 7 if (!crnt) 8 count++; 9 else { 10 if (count >= 3) n -= (count - 3) / 2 + 1; 11 if (n <= 0) return true; 12 count = 0; 13 } 14 } 15 return false; 16 } 17 };