Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1396 from loczek/605-Can-Place-Flowers
Browse files Browse the repository at this point in the history
Create: 605-Can-Place-Flowers.ts
  • Loading branch information
Ahmad-A0 authored Nov 2, 2022
2 parents 869a3ce + d219e6f commit bd5452d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions typescript/605-Can-Place-Flowers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function canPlaceFlowers(flowerbed: number[], n: number): boolean {
flowerbed = [0, ...flowerbed, 0];

for (let i = 1; i < flowerbed.length - 1; i++) {
if (
flowerbed[i - 1] == 0 &&
flowerbed[i + 1] === 0 &&
flowerbed[i] === 0
) {
flowerbed[i] = 1;
n -= 1;
}
}

return n <= 0;
}

0 comments on commit bd5452d

Please sign in to comment.