标签:back rac for ack unique ++ nbsp ons OLE
backtrack
1 class Solution { 2 List<List<Integer>> res = new ArrayList<>(); 3 public List<List<Integer>> permuteUnique(int[] nums) { 4 Arrays.sort(nums); 5 backtrack(nums, new ArrayList<>(), new boolean[nums.length]); 6 return res; 7 } 8 9 public void backtrack(int[] nums, List<Integer> list, boolean[] used) { 10 if(list.size() == nums.length) { 11 res.add(new ArrayList<>(list)); 12 } 13 for(int i = 0; i < nums.length; i++) { 14 if(used[i] || (i > 0 && nums[i-1] == nums[i] && !used[i-1])) continue; 15 used[i] = true; 16 list.add(nums[i]); 17 backtrack(nums, list, used); 18 list.remove(list.size() - 1); 19 used[i] = false; 20 } 21 } 22 }
标签:back rac for ack unique ++ nbsp ons OLE
原文地址:https://www.cnblogs.com/goPanama/p/9625380.html