From 355f4db077da9f90ba53767c3e26fb43a21dab27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BD=A9=E8=BE=95=E9=BE=99=E5=84=BF?= Date: Fri, 22 Sep 2023 11:21:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E8=A7=84=E5=88=92=EF=BC=88?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E7=89=88=EF=BC=89--=20=E6=96=90=E6=B3=A2?= =?UTF-8?q?=E9=82=A3=E5=A5=91=E7=B1=BB=E5=9E=8B=20--=20=E7=88=AC=E6=A5=BC?= =?UTF-8?q?=E6=A2=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leetcode/editor/cn/ClimbingStairs.java | 62 +++++++++++++++++++ .../editor/cn/doc/content/ClimbingStairs.md | 35 +++++++++++ 2 files changed, 97 insertions(+) create mode 100644 dynamic-programming/src/leetcode/editor/cn/ClimbingStairs.java create mode 100644 dynamic-programming/src/leetcode/editor/cn/doc/content/ClimbingStairs.md diff --git a/dynamic-programming/src/leetcode/editor/cn/ClimbingStairs.java b/dynamic-programming/src/leetcode/editor/cn/ClimbingStairs.java new file mode 100644 index 0000000..d5ab83e --- /dev/null +++ b/dynamic-programming/src/leetcode/editor/cn/ClimbingStairs.java @@ -0,0 +1,62 @@ +//

假设你正在爬楼梯。需要 n 阶你才能到达楼顶。

+// +//

每次你可以爬 12 个台阶。你有多少种不同的方法可以爬到楼顶呢?

+// +//

 

+// +//

示例 1:

+// +//
+//输入:n = 2
+//输出:2
+//解释:有两种方法可以爬到楼顶。
+//1. 1 阶 + 1 阶
+//2. 2 阶
+// +//

示例 2:

+// +//
+//输入:n = 3
+//输出:3
+//解释:有三种方法可以爬到楼顶。
+//1. 1 阶 + 1 阶 + 1 阶
+//2. 1 阶 + 2 阶
+//3. 2 阶 + 1 阶
+//
+// +//

 

+// +//

提示:

+// +// +// +//
Related Topics
  • 记忆化搜索
  • 数学
  • 动态规划

  • 👍 3256
  • 👎 0
  • +package leetcode.editor.cn; + +// 70:爬楼梯 +public class ClimbingStairs { + public static void main(String[] args) { + Solution solution = new ClimbingStairs().new Solution(); + // TO TEST + } + + //leetcode submit region begin(Prohibit modification and deletion) + class Solution { + public int climbStairs(int n) { + if (n < 3) { + return n; + } + int[] arr = new int[n]; + arr[0] = 1; + arr[1] = 2; + for (int i = 2; i < n; i++) { + arr[i] = arr[i - 1] + arr[i - 2]; + } + return arr[n - 1]; + } + } +//leetcode submit region end(Prohibit modification and deletion) + +} diff --git a/dynamic-programming/src/leetcode/editor/cn/doc/content/ClimbingStairs.md b/dynamic-programming/src/leetcode/editor/cn/doc/content/ClimbingStairs.md new file mode 100644 index 0000000..d419f8b --- /dev/null +++ b/dynamic-programming/src/leetcode/editor/cn/doc/content/ClimbingStairs.md @@ -0,0 +1,35 @@ +

    假设你正在爬楼梯。需要 n 阶你才能到达楼顶。

    + +

    每次你可以爬 12 个台阶。你有多少种不同的方法可以爬到楼顶呢?

    + +

     

    + +

    示例 1:

    + +
    +输入:n = 2
    +输出:2
    +解释:有两种方法可以爬到楼顶。
    +1. 1 阶 + 1 阶
    +2. 2 阶
    + +

    示例 2:

    + +
    +输入:n = 3
    +输出:3
    +解释:有三种方法可以爬到楼顶。
    +1. 1 阶 + 1 阶 + 1 阶
    +2. 1 阶 + 2 阶
    +3. 2 阶 + 1 阶
    +
    + +

     

    + +

    提示:

    + + + +
    Related Topics
  • 记忆化搜索
  • 数学
  • 动态规划

  • 👍 3256
  • 👎 0
  • \ No newline at end of file