![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
回溯
回溯
_Charison
这个作者很懒,什么都没留下…
展开
-
leetcode 341. 扁平化嵌套列表迭代器
@(labuladong的算法小抄)[回溯]leetcode 341. 扁平化嵌套列表迭代器题目描述解题思路参考:labuladong的算法小抄P345DFS递归相当于遍历一棵多叉树的所有叶子节点。/** * // This is the interface that allows for creating nested lists. * // You should not implement it, or speculate about its implementation * pu原创 2021-03-10 18:09:46 · 81 阅读 · 0 评论 -
leetcode 22. 括号生成
@(labuladong的算法小抄)[回溯]leetcode 22. 括号生成题目描述解题思路参考:labuladong的算法小抄P306class Solution { List<String> res; public List<String> generateParenthesis(int n) { res = new LinkedList<>(); String track = ""; b原创 2021-03-10 18:09:03 · 55 阅读 · 0 评论 -
leetcode 37. 解数独
@(labuladong的算法小抄)[回溯]leetcode 37. 解数独题目描述解题思路参考:labuladong的算法小抄P301解数独和n皇后思路的区别:n皇后需要遍历的路径是所有行,选择列表是某一行的每一列,因为n皇后是要将Q放在这一行的某一个列上;而解数独需要遍历的路径是9*9的每一个格子,选择列表是1~9这九个数字,因为解数独是要填满每个格子,每个格子有9种选择。class Solution { public void solveSudoku(char[][] bo原创 2021-03-10 18:08:30 · 101 阅读 · 0 评论 -
leetcode 77. 组合
@(labuladong的算法小抄)[回溯]leetcode 77. 组合题目描述解题思路参考:labuladong的算法小抄P293class Solution { List<List<Integer>> res; public List<List<Integer>> combine(int n, int k) { res = new LinkedList<>(); LinkedList原创 2021-03-10 18:06:33 · 61 阅读 · 0 评论 -
leetcode 78. 子集
@(labuladong的算法小抄)[回溯]leetcode 78. 子集题目描述解题思路参考:labuladong的算法小抄P293class Solution { List<List<Integer>> res; public List<List<Integer>> subsets(int[] nums) { res = new LinkedList<>(); LinkedList&l原创 2021-03-09 20:24:42 · 79 阅读 · 0 评论 -
leetcode 51.N皇后
@(labuladong的算法小抄)[回溯]leetcode 51.N皇后题目描述解题思路参考https://labuladong.gitbook.io/algo/di-ling-zhang-bi-du-xi-lie/hui-su-suan-fa-xiang-jie-xiu-ding-ban回溯class Solution { public List<List<String>> res = new ArrayList<>(); publ原创 2021-03-09 20:24:10 · 195 阅读 · 0 评论 -
leetcode 46. 全排列
@(labuladong的算法小抄)[回溯]leetcode 46. 全排列题目描述解题思路参考https://labuladong.gitbook.io/algo/di-ling-zhang-bi-du-xi-lie/hui-su-suan-fa-xiang-jie-xiu-ding-ban回溯法class Solution { private List<List<Integer>> res; /* 主函数,输入一组不重复的数组,返回它们的全排列 *原创 2021-03-09 20:22:47 · 80 阅读 · 0 评论 -
leetcode 494. 目标和
@(labuladong的算法小抄)[回溯, dp]leetcode 494. 目标和题目描述解题思路参考:labuladong的算法小抄P207本题可以很容易画出一棵决策树:下面的方法都相当于在遍历这棵决策树。回溯 P207class Solution { private int res = 0; public int findTargetSumWays(int[] nums, int S) { if (nums.length == 0) ret原创 2021-03-04 15:07:24 · 140 阅读 · 0 评论