//方法一 boolcanPlaceFlowers(vector<int>& flowerbed, int n){ if (!n) returntrue; int len = flowerbed.size(); if (len < n) returnfalse; int cnt = 0; for (int i = 0; i < len; i += 2) { if (!flowerbed[i]) { if (i == len-1 || !flowerbed[i+1]) cnt++; else i++; } } return cnt >= n; }