Skip to content

Commit fa56f9c

Browse files
authored
feat: add php solution to lc problem: No.0605 (doocs#1041)
1 parent 1d0c9e9 commit fa56f9c

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

solution/0600-0699/0605.Can Place Flowers/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,31 @@ func canPlaceFlowers(flowerbed []int, n int) bool {
123123
}
124124
```
125125

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+
126151
### **...**
127152

128153
```

solution/0600-0699/0605.Can Place Flowers/README_EN.md

+25
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,31 @@ func canPlaceFlowers(flowerbed []int, n int) bool {
104104
}
105105
```
106106

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+
107132
### **...**
108133

109134
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}

0 commit comments

Comments
 (0)