Copy List with Random Pointer @ LeetCode (Python)
Substring with Concatenation of All Words @ LeetCode (Python)

Climbing Stairs @ LeetCode (Python)

kitt posted @ 2014年3月05日 23:53 in LeetCode , 2212 阅读

动态规划或递归。

class Solution:
    # @param n, an integer
    # @return an integer
    def climbStairs(self, n):
        dp = [0, 1, 2]
        i = 3
        while i <= n:
            dp.append(dp[i-1] + dp[i-2])
            i += 1
        return dp[n]

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter