diff --git a/solution/0000-0099/0011.Container With Most Water/README.md b/solution/0000-0099/0011.Container With Most Water/README.md index 4d81674da317f..6dbd8cf41fce7 100644 --- a/solution/0000-0099/0011.Container With Most Water/README.md +++ b/solution/0000-0099/0011.Container With Most Water/README.md @@ -206,6 +206,35 @@ public class Solution { } ``` +```php +class Solution { + /** + * @param int[] $height + * @return int + */ + + function maxArea($height) { + $left = 0; + $right = count($height) - 1; + $maxArea = 0; + + while ($left < $right) { + $area = min($height[$left], $height[$right]) * ($right - $left); + + $maxArea = max($maxArea, $area); + + if ($height[$left] < $height[$right]) { + $left++; + } else { + $right--; + } + } + + return $maxArea; + } +} +``` + diff --git a/solution/0000-0099/0011.Container With Most Water/README_EN.md b/solution/0000-0099/0011.Container With Most Water/README_EN.md index 68cdb99432b7d..f321d2f5d264a 100644 --- a/solution/0000-0099/0011.Container With Most Water/README_EN.md +++ b/solution/0000-0099/0011.Container With Most Water/README_EN.md @@ -201,6 +201,35 @@ public class Solution { } ``` +```php +class Solution { + /** + * @param int[] $height + * @return int + */ + + function maxArea($height) { + $left = 0; + $right = count($height) - 1; + $maxArea = 0; + + while ($left < $right) { + $area = min($height[$left], $height[$right]) * ($right - $left); + + $maxArea = max($maxArea, $area); + + if ($height[$left] < $height[$right]) { + $left++; + } else { + $right--; + } + } + + return $maxArea; + } +} +``` + diff --git a/solution/0000-0099/0011.Container With Most Water/Solution.php b/solution/0000-0099/0011.Container With Most Water/Solution.php new file mode 100644 index 0000000000000..320347510d2fa --- /dev/null +++ b/solution/0000-0099/0011.Container With Most Water/Solution.php @@ -0,0 +1,26 @@ +class Solution { + /** + * @param int[] $height + * @return int + */ + + function maxArea($height) { + $left = 0; + $right = count($height) - 1; + $maxArea = 0; + + while ($left < $right) { + $area = min($height[$left], $height[$right]) * ($right - $left); + + $maxArea = max($maxArea, $area); + + if ($height[$left] < $height[$right]) { + $left++; + } else { + $right--; + } + } + + return $maxArea; + } +} diff --git a/solution/0000-0099/0012.Integer to Roman/README.md b/solution/0000-0099/0012.Integer to Roman/README.md index 6e406775637ec..1002a00bb1425 100644 --- a/solution/0000-0099/0012.Integer to Roman/README.md +++ b/solution/0000-0099/0012.Integer to Roman/README.md @@ -181,6 +181,44 @@ public class Solution { } ``` +```php +class Solution { + /** + * @param int $num + * @return string + */ + + function intToRoman($num) { + $values = [ + 'M' => 1000, + 'CM' => 900, + 'D' => 500, + 'CD' => 400, + 'C' => 100, + 'XC' => 90, + 'L' => 50, + 'XL' => 40, + 'X' => 10, + 'IX' => 9, + 'V' => 5, + 'IV' => 4, + 'I' => 1, + ]; + + $result = ''; + + foreach ($values as $roman => $value) { + while ($num >= $value) { + $result .= $roman; + $num -= $value; + } + } + + return $result; + } +} +``` + diff --git a/solution/0000-0099/0012.Integer to Roman/README_EN.md b/solution/0000-0099/0012.Integer to Roman/README_EN.md index 110d2047b445c..5d2bbfa90b174 100644 --- a/solution/0000-0099/0012.Integer to Roman/README_EN.md +++ b/solution/0000-0099/0012.Integer to Roman/README_EN.md @@ -168,6 +168,44 @@ public class Solution { } ``` +```php +class Solution { + /** + * @param int $num + * @return string + */ + + function intToRoman($num) { + $values = [ + 'M' => 1000, + 'CM' => 900, + 'D' => 500, + 'CD' => 400, + 'C' => 100, + 'XC' => 90, + 'L' => 50, + 'XL' => 40, + 'X' => 10, + 'IX' => 9, + 'V' => 5, + 'IV' => 4, + 'I' => 1, + ]; + + $result = ''; + + foreach ($values as $roman => $value) { + while ($num >= $value) { + $result .= $roman; + $num -= $value; + } + } + + return $result; + } +} +``` + diff --git a/solution/0000-0099/0012.Integer to Roman/Solution.php b/solution/0000-0099/0012.Integer to Roman/Solution.php new file mode 100644 index 0000000000000..1f0523d2f333b --- /dev/null +++ b/solution/0000-0099/0012.Integer to Roman/Solution.php @@ -0,0 +1,35 @@ +class Solution { + /** + * @param int $num + * @return string + */ + + function intToRoman($num) { + $values = [ + 'M' => 1000, + 'CM' => 900, + 'D' => 500, + 'CD' => 400, + 'C' => 100, + 'XC' => 90, + 'L' => 50, + 'XL' => 40, + 'X' => 10, + 'IX' => 9, + 'V' => 5, + 'IV' => 4, + 'I' => 1, + ]; + + $result = ''; + + foreach ($values as $roman => $value) { + while ($num >= $value) { + $result .= $roman; + $num -= $value; + } + } + + return $result; + } +}