leet回溯
ldd儆儆
这个作者很懒,什么都没留下…
展开
-
leet47:全排列 II
public List<List<Integer>> permuteUnique(int[] nums) { List<List<Integer>> res = new ArrayList<>(); Arrays.sort(nums); int[] visited = new int[nums.length]; ...原创 2019-12-27 16:11:34 · 96 阅读 · 0 评论 -
leet40:组合总和 II
public List<List<Integer>> combinationSum2(int[] candidates, int target) { List<List<Integer>> lists = new ArrayList<>(); if (candidates == null || candidates.le...原创 2019-12-27 16:03:01 · 92 阅读 · 0 评论 -
leet39:组合总和
public static List<List<Integer>> combinationSum(int[] candidates, int target) { List<List<Integer>> res = new ArrayList<>(); if(candidates == null || candidates...原创 2019-12-27 15:48:34 · 97 阅读 · 0 评论 -
leet46:全排列
public static void backtrack(int n, ArrayList<Integer> list, List<List<Integer>> lists, int first) { // if all ...原创 2019-12-27 14:34:59 · 203 阅读 · 0 评论 -
leet22:括号生成
public static void backtrack1(String cur,int left,int right,List<String> ans){ if (left == 0 && right == 0) { ans.add(cur); return; } if (left > 0){ ...原创 2019-12-26 17:20:20 · 75 阅读 · 0 评论 -
leet90:子集 II
public List<List<Integer>> subsetsWithDup(int[] nums) { List<List<Integer>> ans = new ArrayList<>(); Arrays.sort(nums); //排序 backtrack(nums, 0, new ArrayList...原创 2019-12-26 16:22:13 · 94 阅读 · 0 评论 -
leet78:子集
public static List<List<Integer>> subsets(int[] nums) { List<List<Integer>> lists = new ArrayList<>(); backtrack(0, nums, lists, new ArrayList<Integer>());...原创 2019-12-26 15:51:05 · 97 阅读 · 0 评论 -
leet22:括号生成
public List<String> generateParenthesis(int n) { List<String> ans = new ArrayList<>(); backtrack(ans, "", 0, 0, n); return ans; } public static ...原创 2019-12-23 16:11:23 · 86 阅读 · 0 评论