diff --git a/solution/0000-0099/0070.Climbing Stairs/README.md b/solution/0000-0099/0070.Climbing Stairs/README.md index 5d38d403d03f1..c9da84292b593 100644 --- a/solution/0000-0099/0070.Climbing Stairs/README.md +++ b/solution/0000-0099/0070.Climbing Stairs/README.md @@ -170,6 +170,27 @@ impl Solution { } ``` +### **PHP** + +```php +class Solution { + /** + * @param Integer $n + * @return Integer + */ + function climbStairs($n) { + if ($n <= 2) { + return $n; + } + $dp = [0, 1, 2]; + for ($i = 3; $i <= $n; $i++) { + $dp[$i] = $dp[$i - 2] + $dp[$i - 1]; + } + return $dp[$n]; + } +} +``` + ### **...** ``` diff --git a/solution/0000-0099/0070.Climbing Stairs/README_EN.md b/solution/0000-0099/0070.Climbing Stairs/README_EN.md index 0bb7941b00182..7770e513b529b 100644 --- a/solution/0000-0099/0070.Climbing Stairs/README_EN.md +++ b/solution/0000-0099/0070.Climbing Stairs/README_EN.md @@ -145,6 +145,27 @@ impl Solution { } ``` +### **PHP** + +```php +class Solution { + /** + * @param Integer $n + * @return Integer + */ + function climbStairs($n) { + if ($n <= 2) { + return $n; + } + $dp = [0, 1, 2]; + for ($i = 3; $i <= $n; $i++) { + $dp[$i] = $dp[$i - 2] + $dp[$i - 1]; + } + return $dp[$n]; + } +} +``` + ### **...** ``` diff --git a/solution/0000-0099/0070.Climbing Stairs/Solution.php b/solution/0000-0099/0070.Climbing Stairs/Solution.php new file mode 100644 index 0000000000000..0217e41120c2c --- /dev/null +++ b/solution/0000-0099/0070.Climbing Stairs/Solution.php @@ -0,0 +1,16 @@ +class Solution { + /** + * @param Integer $n + * @return Integer + */ + function climbStairs($n) { + if ($n <= 2) { + return $n; + } + $dp = [0, 1, 2]; + for ($i = 3; $i <= $n; $i++) { + $dp[$i] = $dp[$i - 2] + $dp[$i - 1]; + } + return $dp[$n]; + } +} \ No newline at end of file