I am trying to learn python and am doing leetcode problems to become more familiar with the syntax. I am getting the error:
NameError: name 'dfs' is not defined
dfs(result, temp, 0, n, k)
I am also not sure if I am declaring the lists correctly or if I should pass self as a parameter to the functions.
class Solution:
def dfs(self, result: List[List[int]], temp:List[int], index: int, n: int, k: int):
for i in range(index + 1, n + 1):
temp.push(i)
if len(temp) == k:
result.push(temp)
temp.pop()
return
else:
dfs(result, temp, i, n, k)
temp.pop()
def combine(self, n: int, k: int) -> List[List[int]]:
result = [[]];
temp = [];
dfs(result, temp, 0, n, k)
return result