Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.

&nbsp;
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]]

&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 6
	-10 &lt;= nums[i] &lt;= 10
	All the integers of nums are unique.


class Solution:
    def permute(self, nums: List[int]) -> List[List[int]]:
        return list(permutations(nums))
class Solution {
    List<List<Integer>> res = new LinkedList<>();

    public List<List<Integer>> permute(int[] nums) {
        ArrayList<Integer> list = new ArrayList<>();
        boolean[] visited = new boolean[nums.length];

        backTrack(nums, list, visited);
        return res;
    }

    private void backTrack(int[] nums, ArrayList<Integer> list, boolean[] visited){
        if(list.size() == nums.length){
            res.add(new ArrayList(list));
            return;
        }
        for(int i = 0; i < nums.length; i++){
            if(!visited[i]){
                visited[i] = true;
                list.add(nums[i]);
                backTrack(nums, list, visited);
                visited[i] = false;
                list.remove(list.size() - 1);
            }
        }
    }
}
class Solution {
public:
    void per(int ind, int n, vector<int>&nums, vector<vector<int>> &ans)
    {
        if(ind==n)
        {
            ans.push_back(nums);
            return;
        }
        for(int i=ind;i<n;i++)
        {
            swap(nums[ind],nums[i]);
            per(ind+1,n,nums,ans);
            swap(nums[ind],nums[i]);
        }
    }
    vector<vector<int>> permute(vector<int>& nums) {
        vector<vector<int>> ans;
        int n=nums.size();
        per(0,n,nums,ans);
        return ans;
    }
};
var permute = function(nums) {
    const output = [];
    
    const backtracking = (current, remaining) => {
        if (!remaining.length) return output.push(current);

        for (let i = 0; i < remaining.length; i++) {
            const newCurrent = [...current];
            const newRemaining = [...remaining];

            newCurrent.push(newRemaining[i]);
            newRemaining.splice(i, 1);

            backtracking(newCurrent, newRemaining);
        }
    }
    
    backtracking([], nums);

    return output;
};
Permutations