HTMLify
LeetCode - Can Place Flowers - C
Views: 2 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <stdbool.h> // @leet start bool canPlaceFlowers(int* flowerbed, int flowerbedSize, int n) { for (int c, i = 0; i < flowerbedSize && n > 0; i++, c = 0) { c += flowerbed[i]; if (i > 0) c += flowerbed[i-1]; if (i < flowerbedSize-1) c += flowerbed[i+1]; if (!c) { flowerbed[i] = 1; n--; } } return !n; } // @leet end |