Skip to content

Commit bd7f01f

Browse files
authored
Merge pull request neetcode-gh#1592 from MukulGaur/create-605-Can-Place-Flowers
Create 605-Can-Place-Flowers.java
2 parents 162931c + da47d60 commit bd7f01f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

java/605-Can-Place-Flowers.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public boolean canPlaceFlowers(int[] flowerbed, int n) {
3+
int size = flowerbed.length;
4+
if(n==0) return true;
5+
for(int i=0; i<size; i++){
6+
if(flowerbed[i]==0 && (i==0 || flowerbed[i-1]==0) && (i==size-1 || flowerbed[i+1]==0)){
7+
n--;
8+
if(n==0) return true;
9+
flowerbed[i]=1;
10+
}
11+
}
12+
return false;
13+
}
14+
}

0 commit comments

Comments
 (0)