跳台阶问题
- 记忆化搜索
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param number int整型
# @return int整型
#
class Solution:
def __init__(self):
self.mem = {}
def jumpFloor(self , number: int) -> int:
# write code here
if number == 0:
return 0
return self.subJumpFloor(number)
def subJumpFloor(self, number: int) -> int:
if number in self.mem:
return self.mem[number]
else:
if number < 0:
return 0
if number == 0:
return 1
else:
self.mem[number] = self.subJumpFloor(number - 1) + self.subJumpFloor(number - 2)
return self.mem[number]