Skip to content

Commit 52c34f3

Browse files
Create 605. Can Place Flowers
1 parent 2b3e981 commit 52c34f3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

605. Can Place Flowers

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
bool canPlaceFlowers(vector<int>& flowerbed, int n) {
4+
int cnt=0;
5+
flowerbed.push_back(0);
6+
flowerbed.insert(flowerbed.begin()+0,0);
7+
for(int i=1; i<flowerbed.size()-1; i++)
8+
{
9+
10+
if(flowerbed[i]==0 && flowerbed[i-1]==0 && flowerbed[i+1]==0)
11+
{
12+
cnt++;
13+
i++;
14+
}
15+
16+
}
17+
if(cnt>=n)
18+
return true;
19+
20+
return false;
21+
}
22+
};

0 commit comments

Comments
 (0)