From bd707f89381c9202e8c5bca784551c73ed9cb08c Mon Sep 17 00:00:00 2001 From: kyrie <783842766@qq.com> Date: Sat, 15 May 2021 12:30:37 +0800 Subject: [PATCH] =?UTF-8?q?Update=200070.=E7=88=AC=E6=A5=BC=E6=A2=AF.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 0070.爬楼梯 Java版本 --- problems/0070.爬楼梯.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/problems/0070.爬楼梯.md b/problems/0070.爬楼梯.md index f0a08f99..3f14075f 100644 --- a/problems/0070.爬楼梯.md +++ b/problems/0070.爬楼梯.md @@ -212,6 +212,22 @@ public: Java: +```Java +class Solution { + public int climbStairs(int n) { + // 跟斐波那契数列一样 + if(n <= 2) return n; + int a = 1, b = 2, sum = 0; + + for(int i = 3; i <= n; i++){ + sum = a + b; + a = b; + b = sum; + } + return b; + } +} +``` Python: