Skip to content

Commit 8c66e75

Browse files
authored
Merge pull request neetcode-gh#1980 from alexprudhomme/0605-can-place-flowers.cs
Create: 0605-can-place-flowers.cs
2 parents 9e0f788 + 259081e commit 8c66e75

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

csharp/0605-can-place-flowers.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class Solution {
2+
public bool CanPlaceFlowers(int[] flowerbed, int n) {
3+
4+
for(int i = 0; i < flowerbed.Length; i++){
5+
if(n == 0) return true;
6+
if((i == 0 || flowerbed[i - 1] == 0) && (flowerbed[i] == 0) && (i == flowerbed.Length - 1 || flowerbed[i + 1] == 0)){
7+
flowerbed[i] = 1;
8+
n--;
9+
}
10+
}
11+
return n == 0;
12+
}
13+
}

0 commit comments

Comments
 (0)