LeetCode 70. Climbing Stairs 爬樓梯
解法一:
class Solution {
public:
int climbStairs(int n) {
int cur=1,prev=0;
for(int i=1;i<=n;++i)
{
int tmp=cur;
cur+=prev;
prev=tmp;
}
return cur;
}
};
解法二:
class Solution {
public:
int climbStairs(int n) {
const double s=sqrt(5);
return floor((pow((s+1)/2,n+1)+pow((1-s)/2,n+1))/s+0.5);
}
};
相關推薦
[LeetCode] 70. Climbing Stairs 爬樓梯
code pytho recursion tin ram pub time stair lee You are climbing a stair case. It takes n steps to reach to the top. Each time you can ei
LeetCode:70. Climbing Stairs(爬樓梯問題)
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways c
leetcode 70 Climbing Stairs (爬樓梯) python3 多種思路(Top down / Bottom up)
class Solution: # def __init__(self): # self.dic = {1:1, 2:2} def climbStairs(se
LeetCode 70. Climbing Stairs 爬樓梯
解法一: class Solution { public: int climbStairs(int n) { int cur=1,prev=0; for(int i=1;i<=n;++i) {
Leetcode 70 Climbing Stairs 爬樓梯的方法(動態規劃)
題目描述:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct
LeetCode 70. Climbing Stairs (爬梯子)
原題 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways
leetCode 70.Climbing Stairs (爬樓梯) 解題思路和方法
Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how
[LeetCode] Min Cost Climbing Stairs 爬樓梯的最小損失
int rom fin [1] case pin cos heap tput On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once
[leetcode 70]Climbing Stairs
col 超時 gin pub bing n-2 consola href rgb You are climbing a stair case. It takes n steps to reach to the top. Each time you can eithe
LeetCode 70:Climbing Stairs
ria san 選擇 bst post take text 樓梯 csdn You are climbing a stair case. It takes n steps to reach to the top. Each time you can eit
[leetcode] 70. Climbing Stairs 解題報告
steps style n-2 遞歸 climb n-1 turn reac pan You are climbing a stair case. It takes n steps to reach to the top. Each time you can either
[Leetcode 70]: Climbing Stairs
div clas lis style tro tair ive script air Description: You are climbing a stair case. It takes n steps to reach to the top. Each time y
[leetcode]70.Climbing Stairs
ret reac The solution 計算 not 動態規劃 man return 題目 You are climbing a stair case. It takes n steps to reach to the top. Each time you can ei
LeetCode 70. Climbing Stairs
nat step tair stair there mission not str sta 分析 難度 易 來源 https://leetcode.com/problems/climbing-stairs/ 題目 You are climbing a stair case.
#LeetCode# 70. Climbing Stairs
https://leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It takes n steps to reach to the top. Each time you can e
[leetcode]70. Climbing Stairs
備忘錄方法(自頂向下的動態規劃) public class Solution { public int climbStairs(int n) { int memo[] = new int[n + 1]; return climb_Stairs(0,
[LeetCode]70. Climbing Stairs 斐波那契數列&&動態規劃
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct
動態迴歸Leetcode 70 Climbing Stairs
Leetcode 70 Climbing Stairs Problem Description: 爬樓梯:一次可以爬1-2層樓梯,求出爬到最高一層的樓梯n時需要的步數。 具體的題目資訊: https://leetcode.com/problems/climbing-
Leetcode 70. Climbing Stairs-每次能走1步或2步臺階,輸入n,求總的方法數
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct w
LeetCode-70. Climbing Stairs (Java)
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct