摘要:
class Solution { private List<String> res = new LinkedList<>(); public List<String> readBinaryWatch(int num) { dfs(num, 0, 0, 1, 1, new LinkedList<Int 阅读全文
摘要:
☆☆思路:做完1 和 2之后,直接套模板就完了。刚开始可以把1到9放入数组中,然后回溯搜索。 AC后再去掉数组进行优化。 class Solution { public List<List<Integer>> combinationSum3(int k, int n) { List<List<Int 阅读全文
摘要:
思路:回溯搜索 + 剪枝。 注意,回溯做选择的方法,不适用于有 “有重复元素的数组”。因此,重点掌握 常规回溯算法的写法。 class Solution { public List<List<Integer>> combinationSum2(int[] candidates, int target 阅读全文
摘要:
☆☆☆代码: 排序剪枝后效率更高 ~ class Solution { public List<List<Integer>> combinationSum(int[] candidates, int target) { List<List<Integer>> res = new ArrayList< 阅读全文
摘要:
☆☆☆☆思路:回溯 + 剪枝。 如果使用Set去重,不能AC class Solution { public List<List<Integer>> subsetsWithDup(int[] nums) { List<List<Integer>> res = new ArrayList<>(); A 阅读全文
摘要:
☆☆☆思路:回溯算法。注意对比区分这三道题:求排列、求组合、求子集。 求组合 和 求子集 方法的对比: 更新res的位置不同:求组合时,res 的更新是当树到达底端时;而求子集,res的更新是树上每一个节点,走过的路径都是子集的一部分。 求组合 和 求排列 方法的对比: 树的形状不同:排列问题的树比 阅读全文