成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

[LintCode] Climbing Stairs II

chengtao1633 / 1806人閱讀

Problem

A child is running up a staircase with n steps, and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs.

Example

n=3
1+1+1=2+1=1+2=3=3

return 4

Solution
public class Solution {
    /*
     * @param n: An integer
     * @return: An integer
     */
    public int climbStairs2(int n) {
        // write your code here
        int[] dp = new int[n+3];
        dp[0] = 1;
        dp[1] = 1;
        dp[2] = 2;
        for (int i = 3; i <= n; i++) {
            dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
        }
        return dp[n];
    }
};

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/68158.html

相關(guān)文章

  • [LintCode] Climbing Stairs

    摘要:無需動規(guī),無需額外空間,等同于菲波那切數(shù)列。當然嚕,也可以動規(guī),記住就好。 Problem 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 can you ...

    jemygraw 評論0 收藏0
  • [Leetcode] Climbing Stairs 爬樓梯

    摘要:遞歸法復雜度時間空間思路這題幾乎就是求解斐波那契數(shù)列。最簡單的方法就是遞歸。但重復計算時間復雜度高。代碼遞推法復雜度時間空間思路實際上我們求的時候只需要和的值,所以可以減少一些空間啊。 Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time you c...

    tinyq 評論0 收藏0
  • [leetcode] Climbing Stairs

    摘要:實質(zhì)就是把之前出現(xiàn)過的中間結(jié)果記錄,下次再出現(xiàn)相同情況的時候,通過可以只用的時間復雜度得到。表示到達第層樓梯的不同走法。那么題目中每次可以選擇走一步,或者兩步,。從迭代公式可以知道,有兩個,和。 70. Climbing Stairs You are climbing a staircase. It takes n steps to reach to the top.Each tim...

    int64 評論0 收藏0
  • 746. Min Cost Climbing Stairs

    746. Min Cost Climbing Stairs On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay the cost, you can either climb one or two steps. You need to find mini...

    skinner 評論0 收藏0
  • 070. 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 can you climb to the top? Note: Given n will be a positive i...

    jay_tian 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<