题解 | #跳台阶#
跳台阶
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)