62、不同的路径
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
dp = [[0 for _ in range(n)] for _ in range(m)]
dp[0][0] = 0
for i in range(m):
dp[i][0] = 1
for j in range(n):
dp[0][j] = 1
for i in range(1, m):
for j in range(1, n):
dp[i][j] = dp[i-1][j] + dp[i][j-1]
return dp[-1][-1]
70、爬楼梯
class Solution:
def climbStairs(self, n: int) -> int:
f=lambda x:f(x-1)*x if x>=2 else 1
i=r=1
while n>i:
n-=1
r+=f(n)/(f(i)*f(n-i))
i+=1
return int(r)
78、子集
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
return reduce(lambda x, y: x + [i + [y] for i in x], nums, [[]])