File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 205
205
566|[ Reshape the Matrix] ( ./0566-reshape-the-matrix.js ) |Easy|
206
206
567|[ Permutation in String] ( ./0567-permutation-in-string.js ) |Medium|
207
207
599|[ Minimum Index Sum of Two Lists] ( ./0599-minimum-index-sum-of-two-lists.js ) |Easy|
208
+ 605|[ Can Place Flowers] ( ./0605-can-place-flowers.js ) |Easy|
208
209
606|[ Construct String from Binary Tree] ( ./0606-construct-string-from-binary-tree.js ) |Easy|
209
210
617|[ Merge Two Binary Trees] ( ./0617-merge-two-binary-trees.js ) |Easy|
210
211
628|[ Maximum Product of Three Numbers] ( ./0628-maximum-product-of-three-numbers.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 605. Can Place Flowers
3
+ * https://leetcode.com/problems/can-place-flowers/
4
+ * Difficulty: Easy
5
+ *
6
+ * You have a long flowerbed in which some of the plots are planted, and some are not.
7
+ * However, flowers cannot be planted in adjacent plots.
8
+ *
9
+ * Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1
10
+ * means not empty, and an integer n, return true if n new flowers can be planted in
11
+ * the flowerbed without violating the no-adjacent-flowers rule and false otherwise.
12
+ */
13
+
14
+ /**
15
+ * @param {number[] } flowerbed
16
+ * @param {number } n
17
+ * @return {boolean }
18
+ */
19
+ var canPlaceFlowers = function ( flowerbed , n ) {
20
+ let count = 0 ;
21
+ for ( let i = 0 ; i < flowerbed . length ; i ++ ) {
22
+ if ( flowerbed [ i ] === 0 && flowerbed [ i - 1 ] !== 1 && flowerbed [ i + 1 ] !== 1 ) {
23
+ count ++ ;
24
+ flowerbed [ i ] = 1 ;
25
+ }
26
+ }
27
+ return count >= n ;
28
+ } ;
You can’t perform that action at this time.
0 commit comments