Skip to content

Commit 3c1a1fb

Browse files
authored
feat: add php solution to lc problem: No.1189 (doocs#971)
1 parent 3dc6198 commit 3c1a1fb

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

solution/1100-1199/1189.Maximum Number of Balloons/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,30 @@ impl Solution {
202202
}
203203
```
204204

205+
### **PHP**
206+
207+
```php
208+
class Solution {
209+
/**
210+
* @param String $text
211+
* @return Integer
212+
*/
213+
function maxNumberOfBalloons($text) {
214+
$cnt1 = $cnt2 = $cnt3 = $cnt4 = $cnt5 = 0;
215+
for ($i = 0; $i < strlen($text); $i++) {
216+
if ($text[$i] == "b") $cnt1 += 1;
217+
else if ($text[$i] == "a") $cnt2 += 1;
218+
else if ($text[$i] == "l") $cnt3 += 1;
219+
else if ($text[$i] == "o") $cnt4 += 1;
220+
else if ($text[$i] == "n") $cnt5 += 1;
221+
}
222+
$cnt3 = floor($cnt3 / 2);
223+
$cnt4 = floor($cnt4 / 2);
224+
return min($cnt1, $cnt2, $cnt3, $cnt4, $cnt5);
225+
}
226+
}
227+
```
228+
205229
### **...**
206230

207231
```

solution/1100-1199/1189.Maximum Number of Balloons/README_EN.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,30 @@ impl Solution {
193193
}
194194
```
195195

196+
### **PHP**
197+
198+
```php
199+
class Solution {
200+
/**
201+
* @param String $text
202+
* @return Integer
203+
*/
204+
function maxNumberOfBalloons($text) {
205+
$cnt1 = $cnt2 = $cnt3 = $cnt4 = $cnt5 = 0;
206+
for ($i = 0; $i < strlen($text); $i++) {
207+
if ($text[$i] == "b") $cnt1 += 1;
208+
else if ($text[$i] == "a") $cnt2 += 1;
209+
else if ($text[$i] == "l") $cnt3 += 1;
210+
else if ($text[$i] == "o") $cnt4 += 1;
211+
else if ($text[$i] == "n") $cnt5 += 1;
212+
}
213+
$cnt3 = floor($cnt3 / 2);
214+
$cnt4 = floor($cnt4 / 2);
215+
return min($cnt1, $cnt2, $cnt3, $cnt4, $cnt5);
216+
}
217+
}
218+
```
219+
196220
### **...**
197221

198222
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
/**
3+
* @param String $text
4+
* @return Integer
5+
*/
6+
function maxNumberOfBalloons($text) {
7+
$cnt1 = $cnt2 = $cnt3 = $cnt4 = $cnt5 = 0;
8+
for ($i = 0; $i < strlen($text); $i++) {
9+
if ($text[$i] == "b") $cnt1 += 1;
10+
else if ($text[$i] == "a") $cnt2 += 1;
11+
else if ($text[$i] == "l") $cnt3 += 1;
12+
else if ($text[$i] == "o") $cnt4 += 1;
13+
else if ($text[$i] == "n") $cnt5 += 1;
14+
}
15+
$cnt3 = floor($cnt3 / 2);
16+
$cnt4 = floor($cnt4 / 2);
17+
return min($cnt1, $cnt2, $cnt3, $cnt4, $cnt5);
18+
}
19+
}

0 commit comments

Comments
 (0)