mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-03 05:27:55 +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
|
||||
* Author: Krahets (krahets@163.com)
|
||||
*/
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
vector<TreeNode *> res;
|
||||
|
||||
/* 前序遍历 */
|
||||
/* 前序遍历:例题一 */
|
||||
static void preOrder(TreeNode *root) {
|
||||
if (root == nullptr) {
|
||||
return;
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: preorder_find_paths.cpp
|
||||
* File: preorder_traversal_ii_compact.cpp
|
||||
* Created Time: 2023-04-16
|
||||
* Author: Krahets (krahets@163.com)
|
||||
*/
|
||||
@ -9,7 +9,7 @@
|
||||
vector<TreeNode *> path;
|
||||
vector<vector<TreeNode *>> res;
|
||||
|
||||
/* 前序遍历 */
|
||||
/* 前序遍历:例题二 */
|
||||
static void preOrder(TreeNode *root) {
|
||||
if (root == nullptr) {
|
||||
return;
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: preorder_find_constrained_paths.cpp
|
||||
* File: preorder_traversal_iii_compact.cpp
|
||||
* Created Time: 2023-04-16
|
||||
* Author: Krahets (krahets@163.com)
|
||||
*/
|
||||
@ -9,7 +9,7 @@
|
||||
vector<TreeNode *> path;
|
||||
vector<vector<TreeNode *>> res;
|
||||
|
||||
/* 前序遍历 */
|
||||
/* 前序遍历:例题三 */
|
||||
static void preOrder(TreeNode *root) {
|
||||
// 剪枝
|
||||
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
|
||||
* Author: Krahets (krahets@163.com)
|
||||
*/
|
||||
@ -31,7 +31,7 @@ void undoChoice(vector<TreeNode *> &state, TreeNode *choice) {
|
||||
state.pop_back();
|
||||
}
|
||||
|
||||
/* 回溯算法 */
|
||||
/* 回溯算法:例题三 */
|
||||
void backtrack(vector<TreeNode *> &state, vector<TreeNode *> &choices, vector<vector<TreeNode *>> &res) {
|
||||
// 检查是否为解
|
||||
if (isSolution(state)) {
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: preorder_find_nodes.cs
|
||||
* File: preorder_traversal_i_compact.cs
|
||||
* Created Time: 2023-04-17
|
||||
* Author: hpstory (hpstory1024@163.com)
|
||||
*/
|
||||
@ -10,11 +10,11 @@ using System.IO;
|
||||
|
||||
namespace hello_algo.chapter_backtracking;
|
||||
|
||||
public class preorder_find_nodes
|
||||
public class preorder_traversal_i_compact
|
||||
{
|
||||
static List<TreeNode> res;
|
||||
|
||||
/* 前序遍历 */
|
||||
/* 前序遍历:例题一 */
|
||||
static void preOrder(TreeNode root)
|
||||
{
|
||||
if (root == null)
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: preorder_find_paths.cs
|
||||
* File: preorder_traversal_ii_compact.cs
|
||||
* Created Time: 2023-04-17
|
||||
* Author: hpstory (hpstory1024@163.com)
|
||||
*/
|
||||
@ -9,12 +9,12 @@ using NUnit.Framework;
|
||||
|
||||
namespace hello_algo.chapter_backtracking;
|
||||
|
||||
public class preorder_find_paths
|
||||
public class preorder_traversal_ii_compact
|
||||
{
|
||||
static List<TreeNode> path;
|
||||
static List<List<TreeNode>> res;
|
||||
|
||||
/* 前序遍历 */
|
||||
/* 前序遍历:例题二 */
|
||||
static void preOrder(TreeNode root)
|
||||
{
|
||||
if (root == null)
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: preorder_find_constrained_paths.cs
|
||||
* File: preorder_traversal_iii_compact.cs
|
||||
* Created Time: 2023-04-17
|
||||
* Author: hpstory (hpstory1024@163.com)
|
||||
*/
|
||||
@ -9,12 +9,12 @@ using NUnit.Framework;
|
||||
|
||||
namespace hello_algo.chapter_backtracking;
|
||||
|
||||
public class preorder_find_constrained_paths
|
||||
public class preorder_traversal_iii_compact
|
||||
{
|
||||
static List<TreeNode> path;
|
||||
static List<List<TreeNode>> res;
|
||||
|
||||
/* 前序遍历 */
|
||||
/* 前序遍历:例题三 */
|
||||
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
|
||||
* Author: hpstory (hpstory1024@163.com)
|
||||
*/
|
||||
@ -9,7 +9,7 @@ using NUnit.Framework;
|
||||
|
||||
namespace hello_algo.chapter_backtracking;
|
||||
|
||||
public class backtrack_find_constrained_paths
|
||||
public class preorder_traversal_iii_template
|
||||
{
|
||||
/* 判断当前状态是否为解 */
|
||||
static bool isSolution(List<TreeNode> state)
|
||||
@ -41,7 +41,7 @@ public class backtrack_find_constrained_paths
|
||||
state.RemoveAt(state.Count - 1);
|
||||
}
|
||||
|
||||
/* 回溯算法 */
|
||||
/* 回溯算法:例题三 */
|
||||
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
|
||||
* Author: Krahets (krahets@163.com)
|
||||
*/
|
||||
@ -9,10 +9,10 @@ package chapter_backtracking;
|
||||
import include.*;
|
||||
import java.util.*;
|
||||
|
||||
public class preorder_find_nodes {
|
||||
public class preorder_traversal_i_compact {
|
||||
static List<TreeNode> res;
|
||||
|
||||
/* 前序遍历 */
|
||||
/* 前序遍历:例题一 */
|
||||
static void preOrder(TreeNode root) {
|
||||
if (root == null) {
|
||||
return;
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: preorder_find_paths.java
|
||||
* File: preorder_traversal_ii_compact.java
|
||||
* Created Time: 2023-04-16
|
||||
* Author: Krahets (krahets@163.com)
|
||||
*/
|
||||
@ -9,11 +9,11 @@ package chapter_backtracking;
|
||||
import include.*;
|
||||
import java.util.*;
|
||||
|
||||
public class preorder_find_paths {
|
||||
public class preorder_traversal_ii_compact {
|
||||
static List<TreeNode> path;
|
||||
static List<List<TreeNode>> res;
|
||||
|
||||
/* 前序遍历 */
|
||||
/* 前序遍历:例题二 */
|
||||
static void preOrder(TreeNode root) {
|
||||
if (root == null) {
|
||||
return;
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: preorder_find_constrained_paths.java
|
||||
* File: preorder_traversal_iii_compact.java
|
||||
* Created Time: 2023-04-16
|
||||
* Author: Krahets (krahets@163.com)
|
||||
*/
|
||||
@ -9,11 +9,11 @@ package chapter_backtracking;
|
||||
import include.*;
|
||||
import java.util.*;
|
||||
|
||||
public class preorder_find_constrained_paths {
|
||||
public class preorder_traversal_iii_compact {
|
||||
static List<TreeNode> path;
|
||||
static List<List<TreeNode>> res;
|
||||
|
||||
/* 前序遍历 */
|
||||
/* 前序遍历:例题三 */
|
||||
static void preOrder(TreeNode root) {
|
||||
// 剪枝
|
||||
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
|
||||
* Author: Krahets (krahets@163.com)
|
||||
*/
|
||||
@ -9,7 +9,7 @@ package chapter_backtracking;
|
||||
import include.*;
|
||||
import java.util.*;
|
||||
|
||||
public class backtrack_find_constrained_paths {
|
||||
public class preorder_traversal_iii_template {
|
||||
/* 判断当前状态是否为解 */
|
||||
static boolean isSolution(List<TreeNode> state) {
|
||||
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);
|
||||
}
|
||||
|
||||
/* 回溯算法 */
|
||||
/* 回溯算法:例题三 */
|
||||
static void backtrack(List<TreeNode> state, List<TreeNode> choices, List<List<TreeNode>> res) {
|
||||
// 检查是否为解
|
||||
if (isSolution(state)) {
|
||||
@ -1,5 +1,5 @@
|
||||
"""
|
||||
File: preorder_find_nodes.py
|
||||
File: find_nodes-preorder.py
|
||||
Created Time: 2023-04-15
|
||||
Author: Krahets (krahets@163.com)
|
||||
"""
|
||||
@ -11,7 +11,7 @@ from modules import *
|
||||
|
||||
|
||||
def pre_order(root: TreeNode) -> None:
|
||||
"""前序遍历"""
|
||||
"""前序遍历:例题一"""
|
||||
if root is None:
|
||||
return
|
||||
if root.val == 7:
|
||||
@ -1,5 +1,5 @@
|
||||
"""
|
||||
File: preorder_find_paths.py
|
||||
File: find_paths-preorder.py
|
||||
Created Time: 2023-04-15
|
||||
Author: Krahets (krahets@163.com)
|
||||
"""
|
||||
@ -11,7 +11,7 @@ from modules import *
|
||||
|
||||
|
||||
def pre_order(root: TreeNode) -> None:
|
||||
"""前序遍历"""
|
||||
"""前序遍历:例题二"""
|
||||
if root is None:
|
||||
return
|
||||
# 尝试
|
||||
@ -1,5 +1,5 @@
|
||||
"""
|
||||
File: preorder_find_constrained_path.py
|
||||
File: find_constrained_paths_template.py
|
||||
Created Time: 2023-04-15
|
||||
Author: Krahets (krahets@163.com)
|
||||
"""
|
||||
@ -11,7 +11,7 @@ from modules import *
|
||||
|
||||
|
||||
def pre_order(root: TreeNode) -> None:
|
||||
"""前序遍历"""
|
||||
"""前序遍历:例题三"""
|
||||
# 剪枝
|
||||
if root is None or root.val == 3:
|
||||
return
|
||||
@ -1,5 +1,5 @@
|
||||
"""
|
||||
File: backtrack_find_constrained_path.py
|
||||
File: find_constrained_paths_template.py
|
||||
Created Time: 2023-04-15
|
||||
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]]):
|
||||
"""回溯算法"""
|
||||
"""回溯算法:例题三"""
|
||||
# 检查是否为解
|
||||
if is_solution(state):
|
||||
# 记录解
|
||||
Reference in New Issue
Block a user