Given an array nums without repeating numbers, return all possible permutations of it.You can return answers in any order.
Example 1:
Input: nums = [1,2,3]
Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
Example 2:
Input: nums = [0,1]
Output: [[0,1],[1,0]]
Example 3:
Input: nums = [1]
Output: [[1]]
class Solution:def permute(self, nums: List[int]) -> List[List[int]]:res = []n = len(nums)def back_dfs(first=0):if first ==n:res.append(nums[:])for i in range(first,n):nums[first],nums[i] = nums[i],nums[first]back_dfs(first+1)nums[first], nums[i] = nums[i], nums[first]back_dfs()return res