package BackTracking;
import java.util.*;
/*
Given a collection of distinct integers, return all possible permutations.
Example:
Input: [1,2,3]
Output:
[
[1,2,3],
[1,3,2],
[2,1,3],
[2,3,1],
[3,1,2],
[3,2,1]
]
*/
public class Permutations {
class Solution {
public List> permute(int[] nums) {
List
> permutations = new ArrayList<>();
boolean[] seen = new boolean[nums.length];
if(nums == null || nums.length == 0) {
return permutations;
}
findPermutations(nums, permutations, new ArrayList<>(), seen);
return permutations;
}
private void findPermutations (int[] nums, List
> permutations, List