mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 22:28:40 +08:00 
			
		
		
		
	Rename the naming of the coding files
in backtracking algorithm. Add the typedef to docs.
This commit is contained in:
		@ -1,5 +1,5 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * File: preorder_find_nodes.cpp
 | 
					 * File: preorder_traversal_i_compact.cpp
 | 
				
			||||||
 * Created Time: 2023-04-16
 | 
					 * Created Time: 2023-04-16
 | 
				
			||||||
 * Author: Krahets (krahets@163.com)
 | 
					 * Author: Krahets (krahets@163.com)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -8,7 +8,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
vector<TreeNode *> res;
 | 
					vector<TreeNode *> res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* 前序遍历 */
 | 
					/* 前序遍历:例题一 */
 | 
				
			||||||
static void preOrder(TreeNode *root) {
 | 
					static void preOrder(TreeNode *root) {
 | 
				
			||||||
    if (root == nullptr) {
 | 
					    if (root == nullptr) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * File: preorder_find_paths.cpp
 | 
					 * File: preorder_traversal_ii_compact.cpp
 | 
				
			||||||
 * Created Time: 2023-04-16
 | 
					 * Created Time: 2023-04-16
 | 
				
			||||||
 * Author: Krahets (krahets@163.com)
 | 
					 * Author: Krahets (krahets@163.com)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -9,7 +9,7 @@
 | 
				
			|||||||
vector<TreeNode *> path;
 | 
					vector<TreeNode *> path;
 | 
				
			||||||
vector<vector<TreeNode *>> res;
 | 
					vector<vector<TreeNode *>> res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* 前序遍历 */
 | 
					/* 前序遍历:例题二 */
 | 
				
			||||||
static void preOrder(TreeNode *root) {
 | 
					static void preOrder(TreeNode *root) {
 | 
				
			||||||
    if (root == nullptr) {
 | 
					    if (root == nullptr) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * File: preorder_find_constrained_paths.cpp
 | 
					 * File: preorder_traversal_iii_compact.cpp
 | 
				
			||||||
 * Created Time: 2023-04-16
 | 
					 * Created Time: 2023-04-16
 | 
				
			||||||
 * Author: Krahets (krahets@163.com)
 | 
					 * Author: Krahets (krahets@163.com)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -9,7 +9,7 @@
 | 
				
			|||||||
vector<TreeNode *> path;
 | 
					vector<TreeNode *> path;
 | 
				
			||||||
vector<vector<TreeNode *>> res;
 | 
					vector<vector<TreeNode *>> res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* 前序遍历 */
 | 
					/* 前序遍历:例题三 */
 | 
				
			||||||
static void preOrder(TreeNode *root) {
 | 
					static void preOrder(TreeNode *root) {
 | 
				
			||||||
    // 剪枝
 | 
					    // 剪枝
 | 
				
			||||||
    if (root == nullptr || root->val == 3) {
 | 
					    if (root == nullptr || root->val == 3) {
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * File: backtrack_find_constrained_paths.cpp
 | 
					 * File: preorder_traversal_iii_template.cpp
 | 
				
			||||||
 * Created Time: 2023-04-16
 | 
					 * Created Time: 2023-04-16
 | 
				
			||||||
 * Author: Krahets (krahets@163.com)
 | 
					 * Author: Krahets (krahets@163.com)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -31,7 +31,7 @@ void undoChoice(vector<TreeNode *> &state, TreeNode *choice) {
 | 
				
			|||||||
    state.pop_back();
 | 
					    state.pop_back();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* 回溯算法 */
 | 
					/* 回溯算法:例题三 */
 | 
				
			||||||
void backtrack(vector<TreeNode *> &state, vector<TreeNode *> &choices, vector<vector<TreeNode *>> &res) {
 | 
					void backtrack(vector<TreeNode *> &state, vector<TreeNode *> &choices, vector<vector<TreeNode *>> &res) {
 | 
				
			||||||
    // 检查是否为解
 | 
					    // 检查是否为解
 | 
				
			||||||
    if (isSolution(state)) {
 | 
					    if (isSolution(state)) {
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * File: preorder_find_nodes.cs
 | 
					 * File: preorder_traversal_i_compact.cs
 | 
				
			||||||
 * Created Time: 2023-04-17
 | 
					 * Created Time: 2023-04-17
 | 
				
			||||||
 * Author: hpstory (hpstory1024@163.com)
 | 
					 * Author: hpstory (hpstory1024@163.com)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -10,11 +10,11 @@ using System.IO;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace hello_algo.chapter_backtracking;
 | 
					namespace hello_algo.chapter_backtracking;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class preorder_find_nodes
 | 
					public class preorder_traversal_i_compact
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    static List<TreeNode> res;
 | 
					    static List<TreeNode> res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* 前序遍历 */
 | 
					    /* 前序遍历:例题一 */
 | 
				
			||||||
    static void preOrder(TreeNode root)
 | 
					    static void preOrder(TreeNode root)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (root == null)
 | 
					        if (root == null)
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * File: preorder_find_paths.cs
 | 
					 * File: preorder_traversal_ii_compact.cs
 | 
				
			||||||
 * Created Time: 2023-04-17
 | 
					 * Created Time: 2023-04-17
 | 
				
			||||||
 * Author: hpstory (hpstory1024@163.com)
 | 
					 * Author: hpstory (hpstory1024@163.com)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -9,12 +9,12 @@ using NUnit.Framework;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace hello_algo.chapter_backtracking;
 | 
					namespace hello_algo.chapter_backtracking;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class preorder_find_paths
 | 
					public class preorder_traversal_ii_compact
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    static List<TreeNode> path;
 | 
					    static List<TreeNode> path;
 | 
				
			||||||
    static List<List<TreeNode>> res;
 | 
					    static List<List<TreeNode>> res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* 前序遍历 */
 | 
					    /* 前序遍历:例题二 */
 | 
				
			||||||
    static void preOrder(TreeNode root)
 | 
					    static void preOrder(TreeNode root)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (root == null)
 | 
					        if (root == null)
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * File: preorder_find_constrained_paths.cs
 | 
					 * File: preorder_traversal_iii_compact.cs
 | 
				
			||||||
 * Created Time: 2023-04-17
 | 
					 * Created Time: 2023-04-17
 | 
				
			||||||
 * Author: hpstory (hpstory1024@163.com)
 | 
					 * Author: hpstory (hpstory1024@163.com)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -9,12 +9,12 @@ using NUnit.Framework;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace hello_algo.chapter_backtracking;
 | 
					namespace hello_algo.chapter_backtracking;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class preorder_find_constrained_paths
 | 
					public class preorder_traversal_iii_compact
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    static List<TreeNode> path;
 | 
					    static List<TreeNode> path;
 | 
				
			||||||
    static List<List<TreeNode>> res;
 | 
					    static List<List<TreeNode>> res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* 前序遍历 */
 | 
					    /* 前序遍历:例题三 */
 | 
				
			||||||
    static void preOrder(TreeNode root)
 | 
					    static void preOrder(TreeNode root)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // 剪枝
 | 
					        // 剪枝
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * File: backtrack_find_constrained_paths.cs
 | 
					 * File: preorder_traversal_iii_template.cs
 | 
				
			||||||
 * Created Time: 2023-04-17
 | 
					 * Created Time: 2023-04-17
 | 
				
			||||||
 * Author: hpstory (hpstory1024@163.com)
 | 
					 * Author: hpstory (hpstory1024@163.com)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -9,7 +9,7 @@ using NUnit.Framework;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace hello_algo.chapter_backtracking;
 | 
					namespace hello_algo.chapter_backtracking;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class backtrack_find_constrained_paths
 | 
					public class preorder_traversal_iii_template
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /* 判断当前状态是否为解 */
 | 
					    /* 判断当前状态是否为解 */
 | 
				
			||||||
    static bool isSolution(List<TreeNode> state)
 | 
					    static bool isSolution(List<TreeNode> state)
 | 
				
			||||||
@ -41,7 +41,7 @@ public class backtrack_find_constrained_paths
 | 
				
			|||||||
        state.RemoveAt(state.Count - 1);
 | 
					        state.RemoveAt(state.Count - 1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* 回溯算法 */
 | 
					    /* 回溯算法:例题三 */
 | 
				
			||||||
    static void backtrack(List<TreeNode> state, List<TreeNode> choices, List<List<TreeNode>> res)
 | 
					    static void backtrack(List<TreeNode> state, List<TreeNode> choices, List<List<TreeNode>> res)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // 检查是否为解
 | 
					        // 检查是否为解
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * File: preorder_find_nodes.java
 | 
					 * File: preorder_traversal_i_compact.java
 | 
				
			||||||
 * Created Time: 2023-04-16
 | 
					 * Created Time: 2023-04-16
 | 
				
			||||||
 * Author: Krahets (krahets@163.com)
 | 
					 * Author: Krahets (krahets@163.com)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -9,10 +9,10 @@ package chapter_backtracking;
 | 
				
			|||||||
import include.*;
 | 
					import include.*;
 | 
				
			||||||
import java.util.*;
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class preorder_find_nodes {
 | 
					public class preorder_traversal_i_compact {
 | 
				
			||||||
    static List<TreeNode> res;
 | 
					    static List<TreeNode> res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* 前序遍历 */
 | 
					    /* 前序遍历:例题一 */
 | 
				
			||||||
    static void preOrder(TreeNode root) {
 | 
					    static void preOrder(TreeNode root) {
 | 
				
			||||||
        if (root == null) {
 | 
					        if (root == null) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * File: preorder_find_paths.java
 | 
					 * File: preorder_traversal_ii_compact.java
 | 
				
			||||||
 * Created Time: 2023-04-16
 | 
					 * Created Time: 2023-04-16
 | 
				
			||||||
 * Author: Krahets (krahets@163.com)
 | 
					 * Author: Krahets (krahets@163.com)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -9,11 +9,11 @@ package chapter_backtracking;
 | 
				
			|||||||
import include.*;
 | 
					import include.*;
 | 
				
			||||||
import java.util.*;
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class preorder_find_paths {
 | 
					public class preorder_traversal_ii_compact {
 | 
				
			||||||
    static List<TreeNode> path;
 | 
					    static List<TreeNode> path;
 | 
				
			||||||
    static List<List<TreeNode>> res;
 | 
					    static List<List<TreeNode>> res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* 前序遍历 */
 | 
					    /* 前序遍历:例题二 */
 | 
				
			||||||
    static void preOrder(TreeNode root) {
 | 
					    static void preOrder(TreeNode root) {
 | 
				
			||||||
        if (root == null) {
 | 
					        if (root == null) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * File: preorder_find_constrained_paths.java
 | 
					 * File: preorder_traversal_iii_compact.java
 | 
				
			||||||
 * Created Time: 2023-04-16
 | 
					 * Created Time: 2023-04-16
 | 
				
			||||||
 * Author: Krahets (krahets@163.com)
 | 
					 * Author: Krahets (krahets@163.com)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -9,11 +9,11 @@ package chapter_backtracking;
 | 
				
			|||||||
import include.*;
 | 
					import include.*;
 | 
				
			||||||
import java.util.*;
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class preorder_find_constrained_paths {
 | 
					public class preorder_traversal_iii_compact {
 | 
				
			||||||
    static List<TreeNode> path;
 | 
					    static List<TreeNode> path;
 | 
				
			||||||
    static List<List<TreeNode>> res;
 | 
					    static List<List<TreeNode>> res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* 前序遍历 */
 | 
					    /* 前序遍历:例题三 */
 | 
				
			||||||
    static void preOrder(TreeNode root) {
 | 
					    static void preOrder(TreeNode root) {
 | 
				
			||||||
        // 剪枝
 | 
					        // 剪枝
 | 
				
			||||||
        if (root == null || root.val == 3) {
 | 
					        if (root == null || root.val == 3) {
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * File: backtrack_find_constrained_paths.java
 | 
					 * File: preorder_traversal_iii_template.java
 | 
				
			||||||
 * Created Time: 2023-04-16
 | 
					 * Created Time: 2023-04-16
 | 
				
			||||||
 * Author: Krahets (krahets@163.com)
 | 
					 * Author: Krahets (krahets@163.com)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@ -9,7 +9,7 @@ package chapter_backtracking;
 | 
				
			|||||||
import include.*;
 | 
					import include.*;
 | 
				
			||||||
import java.util.*;
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class backtrack_find_constrained_paths {
 | 
					public class preorder_traversal_iii_template {
 | 
				
			||||||
    /* 判断当前状态是否为解 */
 | 
					    /* 判断当前状态是否为解 */
 | 
				
			||||||
    static boolean isSolution(List<TreeNode> state) {
 | 
					    static boolean isSolution(List<TreeNode> state) {
 | 
				
			||||||
        return !state.isEmpty() && state.get(state.size() - 1).val == 7;
 | 
					        return !state.isEmpty() && state.get(state.size() - 1).val == 7;
 | 
				
			||||||
@ -35,7 +35,7 @@ public class backtrack_find_constrained_paths {
 | 
				
			|||||||
        state.remove(state.size() - 1);
 | 
					        state.remove(state.size() - 1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* 回溯算法 */
 | 
					    /* 回溯算法:例题三 */
 | 
				
			||||||
    static void backtrack(List<TreeNode> state, List<TreeNode> choices, List<List<TreeNode>> res) {
 | 
					    static void backtrack(List<TreeNode> state, List<TreeNode> choices, List<List<TreeNode>> res) {
 | 
				
			||||||
        // 检查是否为解
 | 
					        // 检查是否为解
 | 
				
			||||||
        if (isSolution(state)) {
 | 
					        if (isSolution(state)) {
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
"""
 | 
					"""
 | 
				
			||||||
File: preorder_find_nodes.py
 | 
					File: find_nodes-preorder.py
 | 
				
			||||||
Created Time: 2023-04-15
 | 
					Created Time: 2023-04-15
 | 
				
			||||||
Author: Krahets (krahets@163.com)
 | 
					Author: Krahets (krahets@163.com)
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
@ -11,7 +11,7 @@ from modules import *
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def pre_order(root: TreeNode) -> None:
 | 
					def pre_order(root: TreeNode) -> None:
 | 
				
			||||||
    """前序遍历"""
 | 
					    """前序遍历:例题一"""
 | 
				
			||||||
    if root is None:
 | 
					    if root is None:
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    if root.val == 7:
 | 
					    if root.val == 7:
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
"""
 | 
					"""
 | 
				
			||||||
File: preorder_find_paths.py
 | 
					File: find_paths-preorder.py
 | 
				
			||||||
Created Time: 2023-04-15
 | 
					Created Time: 2023-04-15
 | 
				
			||||||
Author: Krahets (krahets@163.com)
 | 
					Author: Krahets (krahets@163.com)
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
@ -11,7 +11,7 @@ from modules import *
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def pre_order(root: TreeNode) -> None:
 | 
					def pre_order(root: TreeNode) -> None:
 | 
				
			||||||
    """前序遍历"""
 | 
					    """前序遍历:例题二"""
 | 
				
			||||||
    if root is None:
 | 
					    if root is None:
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    # 尝试
 | 
					    # 尝试
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
"""
 | 
					"""
 | 
				
			||||||
File: preorder_find_constrained_path.py
 | 
					File: find_constrained_paths_template.py
 | 
				
			||||||
Created Time: 2023-04-15
 | 
					Created Time: 2023-04-15
 | 
				
			||||||
Author: Krahets (krahets@163.com)
 | 
					Author: Krahets (krahets@163.com)
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
@ -11,7 +11,7 @@ from modules import *
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def pre_order(root: TreeNode) -> None:
 | 
					def pre_order(root: TreeNode) -> None:
 | 
				
			||||||
    """前序遍历"""
 | 
					    """前序遍历:例题三"""
 | 
				
			||||||
    # 剪枝
 | 
					    # 剪枝
 | 
				
			||||||
    if root is None or root.val == 3:
 | 
					    if root is None or root.val == 3:
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
"""
 | 
					"""
 | 
				
			||||||
File: backtrack_find_constrained_path.py
 | 
					File: find_constrained_paths_template.py
 | 
				
			||||||
Created Time: 2023-04-15
 | 
					Created Time: 2023-04-15
 | 
				
			||||||
Author: Krahets (krahets@163.com)
 | 
					Author: Krahets (krahets@163.com)
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
@ -36,7 +36,7 @@ def undo_choice(state: list[TreeNode], choice: TreeNode):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def backtrack(state: list[TreeNode], choices: list[TreeNode], res: list[list[TreeNode]]):
 | 
					def backtrack(state: list[TreeNode], choices: list[TreeNode], res: list[list[TreeNode]]):
 | 
				
			||||||
    """回溯算法"""
 | 
					    """回溯算法:例题三"""
 | 
				
			||||||
    # 检查是否为解
 | 
					    # 检查是否为解
 | 
				
			||||||
    if is_solution(state):
 | 
					    if is_solution(state):
 | 
				
			||||||
        # 记录解
 | 
					        # 记录解
 | 
				
			||||||
@ -10,61 +10,61 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "Java"
 | 
					=== "Java"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```java title="preorder_find_nodes.java"
 | 
					    ```java title="preorder_traversal_i_compact.java"
 | 
				
			||||||
    [class]{preorder_find_nodes}-[func]{preOrder}
 | 
					    [class]{preorder_traversal_i_compact}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "C++"
 | 
					=== "C++"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```cpp title="preorder_find_nodes.cpp"
 | 
					    ```cpp title="preorder_traversal_i_compact.cpp"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Python"
 | 
					=== "Python"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```python title="preorder_find_nodes.py"
 | 
					    ```python title="preorder_traversal_i_compact.py"
 | 
				
			||||||
    [class]{}-[func]{pre_order}
 | 
					    [class]{}-[func]{pre_order}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title="preorder_find_nodes.go"
 | 
					    ```go title="preorder_traversal_i_compact.go"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "JavaScript"
 | 
					=== "JavaScript"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```javascript title="preorder_find_nodes.js"
 | 
					    ```javascript title="preorder_traversal_i_compact.js"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "TypeScript"
 | 
					=== "TypeScript"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```typescript title="preorder_find_nodes.ts"
 | 
					    ```typescript title="preorder_traversal_i_compact.ts"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "C"
 | 
					=== "C"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```c title="preorder_find_nodes.c"
 | 
					    ```c title="preorder_traversal_i_compact.c"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "C#"
 | 
					=== "C#"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```csharp title="preorder_find_nodes.cs"
 | 
					    ```csharp title="preorder_traversal_i_compact.cs"
 | 
				
			||||||
    [class]{preorder_find_nodes}-[func]{preOrder}
 | 
					    [class]{preorder_traversal_i_compact}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Swift"
 | 
					=== "Swift"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```swift title="preorder_find_nodes.swift"
 | 
					    ```swift title="preorder_traversal_i_compact.swift"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Zig"
 | 
					=== "Zig"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```zig title="preorder_find_nodes.zig"
 | 
					    ```zig title="preorder_traversal_i_compact.zig"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -84,61 +84,61 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "Java"
 | 
					=== "Java"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```java title="preorder_find_paths.java"
 | 
					    ```java title="preorder_traversal_ii_compact.java"
 | 
				
			||||||
    [class]{preorder_find_paths}-[func]{preOrder}
 | 
					    [class]{preorder_traversal_ii_compact}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "C++"
 | 
					=== "C++"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```cpp title="preorder_find_paths.cpp"
 | 
					    ```cpp title="preorder_traversal_ii_compact.cpp"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Python"
 | 
					=== "Python"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```python title="preorder_find_paths.py"
 | 
					    ```python title="preorder_traversal_ii_compact.py"
 | 
				
			||||||
    [class]{}-[func]{pre_order}
 | 
					    [class]{}-[func]{pre_order}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title="preorder_find_paths.go"
 | 
					    ```go title="preorder_traversal_ii_compact.go"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "JavaScript"
 | 
					=== "JavaScript"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```javascript title="preorder_find_paths.js"
 | 
					    ```javascript title="preorder_traversal_ii_compact.js"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "TypeScript"
 | 
					=== "TypeScript"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```typescript title="preorder_find_paths.ts"
 | 
					    ```typescript title="preorder_traversal_ii_compact.ts"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "C"
 | 
					=== "C"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```c title="preorder_find_paths.c"
 | 
					    ```c title="preorder_traversal_ii_compact.c"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "C#"
 | 
					=== "C#"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```csharp title="preorder_find_paths.cs"
 | 
					    ```csharp title="preorder_traversal_ii_compact.cs"
 | 
				
			||||||
    [class]{preorder_find_paths}-[func]{preOrder}
 | 
					    [class]{preorder_traversal_ii_compact}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Swift"
 | 
					=== "Swift"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```swift title="preorder_find_paths.swift"
 | 
					    ```swift title="preorder_traversal_ii_compact.swift"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Zig"
 | 
					=== "Zig"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```zig title="preorder_find_paths.zig"
 | 
					    ```zig title="preorder_traversal_ii_compact.zig"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -187,61 +187,61 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "Java"
 | 
					=== "Java"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```java title="preorder_find_constrained_paths.java"
 | 
					    ```java title="preorder_traversal_iii_compact.java"
 | 
				
			||||||
    [class]{preorder_find_constrained_paths}-[func]{preOrder}
 | 
					    [class]{preorder_traversal_iii_compact}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "C++"
 | 
					=== "C++"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```cpp title="preorder_find_constrained_paths.cpp"
 | 
					    ```cpp title="preorder_traversal_iii_compact.cpp"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Python"
 | 
					=== "Python"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```python title="preorder_find_constrained_paths.py"
 | 
					    ```python title="preorder_traversal_iii_compact.py"
 | 
				
			||||||
    [class]{}-[func]{pre_order}
 | 
					    [class]{}-[func]{pre_order}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title="preorder_find_constrained_paths.go"
 | 
					    ```go title="preorder_traversal_iii_compact.go"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "JavaScript"
 | 
					=== "JavaScript"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```javascript title="preorder_find_constrained_paths.js"
 | 
					    ```javascript title="preorder_traversal_iii_compact.js"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "TypeScript"
 | 
					=== "TypeScript"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```typescript title="preorder_find_constrained_paths.ts"
 | 
					    ```typescript title="preorder_traversal_iii_compact.ts"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "C"
 | 
					=== "C"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```c title="preorder_find_constrained_paths.c"
 | 
					    ```c title="preorder_traversal_iii_compact.c"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "C#"
 | 
					=== "C#"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```csharp title="preorder_find_constrained_paths.cs"
 | 
					    ```csharp title="preorder_traversal_iii_compact.cs"
 | 
				
			||||||
    [class]{preorder_find_constrained_paths}-[func]{preOrder}
 | 
					    [class]{preorder_traversal_iii_compact}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Swift"
 | 
					=== "Swift"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```swift title="preorder_find_constrained_paths.swift"
 | 
					    ```swift title="preorder_traversal_iii_compact.swift"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Zig"
 | 
					=== "Zig"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```zig title="preorder_find_constrained_paths.zig"
 | 
					    ```zig title="preorder_traversal_iii_compact.zig"
 | 
				
			||||||
    [class]{}-[func]{preOrder}
 | 
					    [class]{}-[func]{preOrder}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -295,23 +295,23 @@ def backtrack(state, choices, res):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "Java"
 | 
					=== "Java"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```java title="backtrack_find_constrained_paths.java"
 | 
					    ```java title="preorder_traversal_iii_template.java"
 | 
				
			||||||
    [class]{backtrack_find_constrained_paths}-[func]{isSolution}
 | 
					    [class]{preorder_traversal_iii_template}-[func]{isSolution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{backtrack_find_constrained_paths}-[func]{recordSolution}
 | 
					    [class]{preorder_traversal_iii_template}-[func]{recordSolution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{backtrack_find_constrained_paths}-[func]{isValid}
 | 
					    [class]{preorder_traversal_iii_template}-[func]{isValid}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{backtrack_find_constrained_paths}-[func]{makeChoice}
 | 
					    [class]{preorder_traversal_iii_template}-[func]{makeChoice}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{backtrack_find_constrained_paths}-[func]{undoChoice}
 | 
					    [class]{preorder_traversal_iii_template}-[func]{undoChoice}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{backtrack_find_constrained_paths}-[func]{backtrack}
 | 
					    [class]{preorder_traversal_iii_template}-[func]{backtrack}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "C++"
 | 
					=== "C++"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```cpp title="backtrack_find_constrained_paths.cpp"
 | 
					    ```cpp title="preorder_traversal_iii_template.cpp"
 | 
				
			||||||
    [class]{}-[func]{isSolution}
 | 
					    [class]{}-[func]{isSolution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{}-[func]{recordSolution}
 | 
					    [class]{}-[func]{recordSolution}
 | 
				
			||||||
@ -327,7 +327,7 @@ def backtrack(state, choices, res):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "Python"
 | 
					=== "Python"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```python title="backtrack_find_constrained_paths.py"
 | 
					    ```python title="preorder_traversal_iii_template.py"
 | 
				
			||||||
    [class]{}-[func]{is_solution}
 | 
					    [class]{}-[func]{is_solution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{}-[func]{record_solution}
 | 
					    [class]{}-[func]{record_solution}
 | 
				
			||||||
@ -343,7 +343,7 @@ def backtrack(state, choices, res):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title="backtrack_find_constrained_paths.go"
 | 
					    ```go title="preorder_traversal_iii_template.go"
 | 
				
			||||||
    [class]{}-[func]{isSolution}
 | 
					    [class]{}-[func]{isSolution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{}-[func]{recordSolution}
 | 
					    [class]{}-[func]{recordSolution}
 | 
				
			||||||
@ -359,7 +359,7 @@ def backtrack(state, choices, res):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "JavaScript"
 | 
					=== "JavaScript"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```javascript title="backtrack_find_constrained_paths.js"
 | 
					    ```javascript title="preorder_traversal_iii_template.js"
 | 
				
			||||||
    [class]{}-[func]{isSolution}
 | 
					    [class]{}-[func]{isSolution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{}-[func]{recordSolution}
 | 
					    [class]{}-[func]{recordSolution}
 | 
				
			||||||
@ -375,7 +375,7 @@ def backtrack(state, choices, res):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "TypeScript"
 | 
					=== "TypeScript"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```typescript title="backtrack_find_constrained_paths.ts"
 | 
					    ```typescript title="preorder_traversal_iii_template.ts"
 | 
				
			||||||
    [class]{}-[func]{isSolution}
 | 
					    [class]{}-[func]{isSolution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{}-[func]{recordSolution}
 | 
					    [class]{}-[func]{recordSolution}
 | 
				
			||||||
@ -391,7 +391,7 @@ def backtrack(state, choices, res):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "C"
 | 
					=== "C"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```c title="backtrack_find_constrained_paths.c"
 | 
					    ```c title="preorder_traversal_iii_template.c"
 | 
				
			||||||
    [class]{}-[func]{isSolution}
 | 
					    [class]{}-[func]{isSolution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{}-[func]{recordSolution}
 | 
					    [class]{}-[func]{recordSolution}
 | 
				
			||||||
@ -407,23 +407,23 @@ def backtrack(state, choices, res):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "C#"
 | 
					=== "C#"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```csharp title="backtrack_find_constrained_paths.cs"
 | 
					    ```csharp title="preorder_traversal_iii_template.cs"
 | 
				
			||||||
    [class]{backtrack_find_constrained_paths}-[func]{isSolution}
 | 
					    [class]{preorder_traversal_iii_template}-[func]{isSolution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{backtrack_find_constrained_paths}-[func]{recordSolution}
 | 
					    [class]{preorder_traversal_iii_template}-[func]{recordSolution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{backtrack_find_constrained_paths}-[func]{isValid}
 | 
					    [class]{preorder_traversal_iii_template}-[func]{isValid}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{backtrack_find_constrained_paths}-[func]{makeChoice}
 | 
					    [class]{preorder_traversal_iii_template}-[func]{makeChoice}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{backtrack_find_constrained_paths}-[func]{undoChoice}
 | 
					    [class]{preorder_traversal_iii_template}-[func]{undoChoice}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{backtrack_find_constrained_paths}-[func]{backtrack}
 | 
					    [class]{preorder_traversal_iii_template}-[func]{backtrack}
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Swift"
 | 
					=== "Swift"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```swift title="backtrack_find_constrained_paths.swift"
 | 
					    ```swift title="preorder_traversal_iii_template.swift"
 | 
				
			||||||
    [class]{}-[func]{isSolution}
 | 
					    [class]{}-[func]{isSolution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{}-[func]{recordSolution}
 | 
					    [class]{}-[func]{recordSolution}
 | 
				
			||||||
@ -439,7 +439,7 @@ def backtrack(state, choices, res):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "Zig"
 | 
					=== "Zig"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```zig title="backtrack_find_constrained_paths.zig"
 | 
					    ```zig title="preorder_traversal_iii_template.zig"
 | 
				
			||||||
    [class]{}-[func]{isSolution}
 | 
					    [class]{}-[func]{isSolution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [class]{}-[func]{recordSolution}
 | 
					    [class]{}-[func]{recordSolution}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user