From 137e4124f5f4623918db1d30fa4b956748616161 Mon Sep 17 00:00:00 2001 From: Qiu-IT Date: Fri, 7 Apr 2023 12:05:46 +0200 Subject: [PATCH] feat: add php solution to lc problem: No.1189 --- .../1189.Maximum Number of Balloons/README.md | 24 +++++++++++++++++++ .../README_EN.md | 24 +++++++++++++++++++ .../Solution.php | 19 +++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 solution/1100-1199/1189.Maximum Number of Balloons/Solution.php diff --git a/solution/1100-1199/1189.Maximum Number of Balloons/README.md b/solution/1100-1199/1189.Maximum Number of Balloons/README.md index b2c0fb379cc9a..f798fa8e00c1e 100644 --- a/solution/1100-1199/1189.Maximum Number of Balloons/README.md +++ b/solution/1100-1199/1189.Maximum Number of Balloons/README.md @@ -202,6 +202,30 @@ impl Solution { } ``` +### **PHP** + +```php +class Solution { + /** + * @param String $text + * @return Integer + */ + function maxNumberOfBalloons($text) { + $cnt1 = $cnt2 = $cnt3 = $cnt4 = $cnt5 = 0; + for ($i = 0; $i < strlen($text); $i++) { + if ($text[$i] == "b") $cnt1 += 1; + else if ($text[$i] == "a") $cnt2 += 1; + else if ($text[$i] == "l") $cnt3 += 1; + else if ($text[$i] == "o") $cnt4 += 1; + else if ($text[$i] == "n") $cnt5 += 1; + } + $cnt3 = floor($cnt3 / 2); + $cnt4 = floor($cnt4 / 2); + return min($cnt1, $cnt2, $cnt3, $cnt4, $cnt5); + } +} +``` + ### **...** ``` diff --git a/solution/1100-1199/1189.Maximum Number of Balloons/README_EN.md b/solution/1100-1199/1189.Maximum Number of Balloons/README_EN.md index 98fe399a40bac..c2e44300a8da5 100644 --- a/solution/1100-1199/1189.Maximum Number of Balloons/README_EN.md +++ b/solution/1100-1199/1189.Maximum Number of Balloons/README_EN.md @@ -193,6 +193,30 @@ impl Solution { } ``` +### **PHP** + +```php +class Solution { + /** + * @param String $text + * @return Integer + */ + function maxNumberOfBalloons($text) { + $cnt1 = $cnt2 = $cnt3 = $cnt4 = $cnt5 = 0; + for ($i = 0; $i < strlen($text); $i++) { + if ($text[$i] == "b") $cnt1 += 1; + else if ($text[$i] == "a") $cnt2 += 1; + else if ($text[$i] == "l") $cnt3 += 1; + else if ($text[$i] == "o") $cnt4 += 1; + else if ($text[$i] == "n") $cnt5 += 1; + } + $cnt3 = floor($cnt3 / 2); + $cnt4 = floor($cnt4 / 2); + return min($cnt1, $cnt2, $cnt3, $cnt4, $cnt5); + } +} +``` + ### **...** ``` diff --git a/solution/1100-1199/1189.Maximum Number of Balloons/Solution.php b/solution/1100-1199/1189.Maximum Number of Balloons/Solution.php new file mode 100644 index 0000000000000..848ab98b9d479 --- /dev/null +++ b/solution/1100-1199/1189.Maximum Number of Balloons/Solution.php @@ -0,0 +1,19 @@ +class Solution { + /** + * @param String $text + * @return Integer + */ + function maxNumberOfBalloons($text) { + $cnt1 = $cnt2 = $cnt3 = $cnt4 = $cnt5 = 0; + for ($i = 0; $i < strlen($text); $i++) { + if ($text[$i] == "b") $cnt1 += 1; + else if ($text[$i] == "a") $cnt2 += 1; + else if ($text[$i] == "l") $cnt3 += 1; + else if ($text[$i] == "o") $cnt4 += 1; + else if ($text[$i] == "n") $cnt5 += 1; + } + $cnt3 = floor($cnt3 / 2); + $cnt4 = floor($cnt4 / 2); + return min($cnt1, $cnt2, $cnt3, $cnt4, $cnt5); + } +} \ No newline at end of file