File tree 3 files changed +70
-0
lines changed
solution/0600-0699/0605.Can Place Flowers
3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,31 @@ func canPlaceFlowers(flowerbed []int, n int) bool {
123
123
}
124
124
```
125
125
126
+ ### ** PHP**
127
+
128
+ ``` php
129
+ class Solution {
130
+ /**
131
+ * @param Integer[] $flowerbed
132
+ * @param Integer $n
133
+ * @return Boolean
134
+ */
135
+ function canPlaceFlowers($flowerbed, $n) {
136
+ array_push($flowerbed, 0);
137
+ array_unshift($flowerbed, 0);
138
+ for ($i = 1; $i < count($flowerbed) - 1; $i++) {
139
+ if ($flowerbed[$i] === 0) {
140
+ if ($flowerbed[$i - 1] === 0 && $flowerbed[$i + 1] === 0) {
141
+ $flowerbed[$i] = 1;
142
+ $n--;
143
+ }
144
+ }
145
+ }
146
+ return $n <= 0;
147
+ }
148
+ }
149
+ ```
150
+
126
151
### ** ...**
127
152
128
153
```
Original file line number Diff line number Diff line change @@ -104,6 +104,31 @@ func canPlaceFlowers(flowerbed []int, n int) bool {
104
104
}
105
105
```
106
106
107
+ ### ** PHP**
108
+
109
+ ``` php
110
+ class Solution {
111
+ /**
112
+ * @param Integer[] $flowerbed
113
+ * @param Integer $n
114
+ * @return Boolean
115
+ */
116
+ function canPlaceFlowers($flowerbed, $n) {
117
+ array_push($flowerbed, 0);
118
+ array_unshift($flowerbed, 0);
119
+ for ($i = 1; $i < count($flowerbed) - 1; $i++) {
120
+ if ($flowerbed[$i] === 0) {
121
+ if ($flowerbed[$i - 1] === 0 && $flowerbed[$i + 1] === 0) {
122
+ $flowerbed[$i] = 1;
123
+ $n--;
124
+ }
125
+ }
126
+ }
127
+ return $n <= 0;
128
+ }
129
+ }
130
+ ```
131
+
107
132
### ** ...**
108
133
109
134
```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /**
3
+ * @param Integer[] $flowerbed
4
+ * @param Integer $n
5
+ * @return Boolean
6
+ */
7
+ function canPlaceFlowers ($flowerbed , $n ) {
8
+ array_push ($flowerbed , 0 );
9
+ array_unshift ($flowerbed , 0 );
10
+ for ($i = 1 ; $i < count ($flowerbed ) - 1 ; $i ++ ) {
11
+ if ($flowerbed [$i ] === 0 ) {
12
+ if ($flowerbed [$i - 1 ] === 0 && $flowerbed [$i + 1 ] === 0 ) {
13
+ $flowerbed [$i ] = 1 ;
14
+ $n -- ;
15
+ }
16
+ }
17
+ }
18
+ return $n <= 0 ;
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments