This commit is contained in:
parent
7e43421a71
commit
4d93e5a150
@ -39,7 +39,7 @@ void main(void) {
|
||||
dfs(curNode->right, result);
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
中序遍历:
|
||||
|
||||
@ -49,7 +49,7 @@ void main(void) {
|
||||
dfs(curNode->right, result);
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
后序遍历:
|
||||
|
||||
@ -59,7 +59,7 @@ void main(void) {
|
||||
printf("%d\n", curNode->val);
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
## 深度优先遍历(迭代法)
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
## [77. 组合](https://leetcode.cn/problems/combinations/description/)
|
||||
|
||||

|
||||

|
||||
|
||||
每个节点存储的数据是什么?是一个 `vector<int>` 类型的数据,代表当前节点的路径。
|
||||
|
||||
@ -43,7 +43,7 @@ void combineDFS(int n, int k, int begin, vector<int> &path,
|
||||
|
||||
我们现在来看看能不能优化。
|
||||
|
||||

|
||||

|
||||
|
||||
在上图的这种情况中,每一层其实都可以剪掉一些不可能的分支,我们可以对每一层循环的终止条件进行限制,从而剪枝。
|
||||
|
||||
@ -98,7 +98,7 @@ Output:
|
||||
|
||||
正确的逻辑应该是如果 `candidates[i] == candidates[i - 1]` 且 `candidates[i - 1]` 使用过,则剪枝。
|
||||
|
||||

|
||||

|
||||
|
||||
那么我们现在要来定义一下什么叫“使用过”。这张图里面有两种“使用过”,第一种使用过是“在树枝上使用过”,第二种使用过是“在数层上使用过”。
|
||||
|
||||
|
@ -88,4 +88,4 @@ vector<vector<int>> S0047::permuteUnique(vector<int> &nums) {
|
||||
|
||||
这道题本来是想不到回溯法的,但是如果某道题能够拆分成多个步骤,每个步骤都在前一步的基础上进行选择,那么就可以用回溯法。
|
||||
|
||||

|
||||

|
||||
|
@ -4,6 +4,6 @@
|
||||
|
||||
## [131. 分割回文串](https://leetcode.cn/problems/palindrome-partitioning/)
|
||||
|
||||

|
||||

|
||||
|
||||
## [93. 复原 IP 地址](https://leetcode.cn/problems/restore-ip-addresses/)
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "s0008_string_to_integer.hpp"
|
||||
|
||||
// 当流程很复杂的时候,画流程图: https://paste.sainnhe.dev/NQxx.png
|
||||
// 当流程很复杂的时候,画流程图: https://share.sainnhe.dev/NQxx.png
|
||||
|
||||
class S0008Automaton {
|
||||
string state = "start";
|
||||
|
Loading…
x
Reference in New Issue
Block a user