backtrack that takes the current permutation curr and the list of numbers nums.curr is equal to the length of nums, add a copy of curr to the answer list ans.nums.curr, add it to curr and call backtrack recursively.curr to backtrack.backtrack initially with an empty curr.ans containing all permutations.