Can Place Flowers LeetCode solution in C++

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

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0