Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1980 from alexprudhomme/0605-can-place…
Browse files Browse the repository at this point in the history
…-flowers.cs

Create: 0605-can-place-flowers.cs
  • Loading branch information
tahsintunan authored Jan 10, 2023
2 parents 9e0f788 + 259081e commit 8c66e75
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions csharp/0605-can-place-flowers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Solution {
public bool CanPlaceFlowers(int[] flowerbed, int n) {

for(int i = 0; i < flowerbed.Length; i++){
if(n == 0) return true;
if((i == 0 || flowerbed[i - 1] == 0) && (flowerbed[i] == 0) && (i == flowerbed.Length - 1 || flowerbed[i + 1] == 0)){
flowerbed[i] = 1;
n--;
}
}
return n == 0;
}
}

0 comments on commit 8c66e75

Please sign in to comment.