class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
res = []
length = len(nums) - 1
def dfs(nums, l):
# base case
if l == length:
res.append(nums)
for i in range(l, length):
# swap
temp = nums[l]
nums[l] = nums[i]
nums[i] = temp
dfs(nums, l+1)
# backtrack
temp = nums[l]
nums[l] = nums[i]
nums[i] = temp
return
dfs(nums, 0)
return res
The output for [1,2,3] is a list of lists where each element is itself [1,2,3] I don't understand.