题解 | #跳台阶#

跳台阶

http://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4

# -*- coding:utf-8 -*-
import math

def C(m, n):
    return math.factorial(m) / (math.factorial(n) * math.factorial(m-n))

class Solution:
    def jumpFloor(self, number):
        # write code here
        if number==0:
            return 0
        else:
            res = 0
            for i in range(number//2 + 1):
                number_of_2 = i
                number_of_1 = number-i
                if number_of_2 > number_of_1:
                    res += C(number_of_2, number_of_1)
                else:
                    res += C(number_of_1, number_of_2)
        return int(res)
    
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务