1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| class Solution { public: bool canPlaceFlowers(vector<int>& f, int n) { for (int i = 0, len = f.size(); i < len && n > 0;) { if (f[i] == 1) { i += 2; } else if (i == len - 1 || f[i + 1] == 0) { n--; i += 2; } else { i += 3; } } return n <= 0; } };
|