用函数版本
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param number int整型
# @return int整型
#
class Solution:
def jumpFloor(self , number: int) -> int:
# write code here
#排列组合问题
#如果是偶数,则1个2级就是n-1种情况,2个2级就是Cn-2(2)种情况,n/2个2级就是1种情况
count = 1
if number%2 == 0:
for i in range(1,(number//2+1)): #i代表2级的数量
count1 = 1
count2 = 1
for j in range(0,i):
count1 *= (number-i-j) #A(n,k)
count2 *= (i-j) #阶乘
count += count1//count2
else :
for i in range(1,((number-1)//2+1)):
count1 = 1
count2 = 1
for j in range(0,i):
count1 *= (number-i-j) #A(n,k)
count2 *= (i-j) #阶乘
count += count1//count2
return count
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param number int整型
# @return int整型
#
class Solution:
def jumpFloor(self , number: int) -> int:
# write code here
#排列组合问题
#如果是偶数,则1个2级就是n-1种情况,2个2级就是Cn-2(2)种情况,n/2个2级就是1种情况
def C_function(n,k):
count1 = 1
count2 = 1
for j in range(0,k):
count1 *= (n-k-j) #A(n,k)
count2 *= (k-j) #阶乘
return (count1//count2)
count = 1
if number%2 == 0:
for i in range(1,(number//2+1)): #i代表2级的数量
# count1 = 1
# count2 = 1
# for j in range(0,i):
# count1 *= (number-i-j) #A(n,k)
# count2 *= (i-j) #阶乘
count += C_function(number,i)
else :
for i in range(1,((number-1)//2+1)):
# count1 = 1
# count2 = 1
# for j in range(0,i):
# count1 *= (number-i-j) #A(n,k)
# count2 *= (i-j) #阶乘
count += C_function(number,i)
return count