Unable to understand where is the bug in this code this is the recursive solution, i've written the same logic in C++ but it's not working in python
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
arr = []
def per(nums,i):
if i == len(nums)-1:
arr.append(nums)
return
for j in range(i,len(nums)):
nums[i],nums[j] = nums[j],nums[i]
per(nums,i+1)
nums[i],nums[j] = nums[j],nums[i]
per(nums,i=0)
return arr
#input: nums = [1,2,3]
#my output: [[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
#correct output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]