From 2a63d9401bbe033ff4b8fbccbdf537076f678039 Mon Sep 17 00:00:00 2001 From: Qiu-IT Date: Wed, 8 Mar 2023 10:44:21 +0100 Subject: [PATCH] feat: add php solution to lc problem: No.0070 --- .../0000-0099/0070.Climbing Stairs/README.md | 21 +++++++++++++++++++ .../0070.Climbing Stairs/README_EN.md | 21 +++++++++++++++++++ .../0070.Climbing Stairs/Solution.php | 16 ++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 solution/0000-0099/0070.Climbing Stairs/Solution.php 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