From 03f037afebff9684e9d64283b1d8d5ec690e684a Mon Sep 17 00:00:00 2001 From: fw_qaq Date: Mon, 10 Apr 2023 15:36:23 +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 --- problems/0070.爬楼梯.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/problems/0070.爬楼梯.md b/problems/0070.爬楼梯.md index c46e3b46..793d3e67 100644 --- a/problems/0070.爬楼梯.md +++ b/problems/0070.爬楼梯.md @@ -454,19 +454,16 @@ public class Solution { ```rust impl Solution { pub fn climb_stairs(n: i32) -> i32 { - if n <= 2 { + if n <= 1 { return n; } - let mut a = 1; - let mut b = 2; - let mut f = 0; - for i in 2..n { + let (mut a, mut b, mut f) = (1, 1, 0); + for _ in 2..=n { f = a + b; a = b; b = f; } - return f; - } + f } ```