not sure about the problem, so might misleading in the title. this question from LC 77. below is my code, but it returns
TypeError: object of type 'NoneType' has no len()
however, if I change path.append(lis[i])
to path + [[lis[i]]
, the code works well and passes the test. what's the difference between these two? Thank you!
def combine( n: int, k: int) -> List[List[int]]:
res = []
lis = [i for i in range(1,n+1)]
visited = set()
def dfs(lis, path):
if len(path) == k:
res.append(path)
return
for i in range(len(lis)):
dfs(lis[i+1:], path.append(lis[i]))
dfs(lis, [])
return res