Skip to content

Commit

Permalink
Create: 605-Can-Place-Flowers.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
loczek committed Nov 1, 2022
1 parent aa1fbd6 commit d219e6f
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 d219e6f

Please sign in to comment.