70. Climbing Stairs

动态规划篇了

class Solution(object):
    def climbStairs(self, n):
        """
        :type n: int
        :rtype: int
        """
        if n == 0:
            return 0
        if n == 1:
            return 1
        if n == 2:
            return 2
        p1 = 1
        p2 = 2
        p = 3
        for i in range(3,n+1):
            p = p1 + p2
            p1, p2 = p2, p
        return p

你可能感兴趣的:(70. Climbing Stairs)