题解 | #跳台阶扩展问题#
跳台阶扩展问题
https://www.nowcoder.com/practice/22243d016f6b47f2a6928b4313c85387
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param number int整型 # @return int整型 # #f(n)=f(n-1)+f(n-2)+f(n-3)+...f(0) #f(n-1) =f(n-2)+f(n-3)+....f(0) #f(n)=2f(n-1) #当台阶数为1时只有1种跳法 class Solution: def jumpFloorII(self , number: int) -> int: # write code here if number <= 0: return -1 if number ==1: return 1 if number >1: return 2*self.jumpFloorII(number-1)