We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d646213 commit 5738ba8Copy full SHA for 5738ba8
605-can-place-flowers.js
@@ -0,0 +1,27 @@
1
+/**
2
+ * @param {number[]} flowerbed
3
+ * @param {number} n
4
+ * @return {boolean}
5
+ */
6
+const canPlaceFlowers = function(flowerbed, n) {
7
+ let count = 0
8
+ const clone = flowerbed
9
+ for(let i = 0; i < clone.length; i++) {
10
+ if(clone[i] === 0) {
11
+ if(i === 0 && (clone[i + 1] === 0 || clone[i+1] == null)){
12
+ count++
13
+ clone[i] = 1
14
+ }
15
+ if(i > 0 && i < clone.length - 1 && clone[i - 1] === 0 && clone[i + 1] === 0) {
16
17
18
19
+ if(i === clone.length - 1 && clone[i - 1] === 0 && clone[i] === 0) {
20
21
22
23
24
25
+
26
+ return count >= n ? true : false
27
+};
0 commit comments