47. Permutations II Posted on 2020-07-01 | Edited on 2021-01-22 | Views: LeetCode 123456789101112131415161718192021class Solution { public List<List<Integer>> permuteUnique(int[] nums) { List<List<Integer>> output =new LinkedList(); List<Integer> nums_lst=new ArrayList<Integer>(); for(int num:nums) nums_lst.add(num); backtrack(nums.length,nums_lst,output,0); return output; } static void backtrack(int n, List<Integer> nums_lst, List<List<Integer>> output, int first){ if (first==n) { if(!output.contains(nums_lst))output.add(new ArrayList<Integer>(nums_lst)); } for (int i = first; i < n; i++) { Collections.swap(nums_lst, first, i); backtrack(n, nums_lst, output, first + 1); Collections.swap(nums_lst, first, i); } }}