題目:

解答:
bool canPlaceFlowers(int* flowerbed, int flowerbedSize, int n) {
int cc = 0;
int cnt = 0;
if (n == 0) {
return true;
}
for (cc = 0; cc < flowerbedSize; cc++) {
cnt = flowerbed[cc];
if (cc > 0) {
cnt += flowerbed[cc - 1];
}
if (cc < (flowerbedSize - 1)) {
cnt += flowerbed[cc + 1];
}
if (cnt == 0) {
n -= 1;
flowerbed[cc] = 1;
if (n == 0) {
return true;
}
}
}
return false;
}