mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-24 21:56:28 +08:00
fix several bugs
This commit is contained in:
parent
51405c0669
commit
5392afd44b
14 changed files with 15 additions and 15 deletions
|
@ -15,7 +15,7 @@ void printFunc(vector *v, void *p) {
|
|||
}
|
||||
|
||||
/* 前序遍历:例题一 */
|
||||
static void preOrder(TreeNode *root) {
|
||||
void preOrder(TreeNode *root) {
|
||||
if (root == NULL) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
add_executable(binary_search_recur binary_search_recur.c)
|
||||
add_executable(hanota hanota.c)
|
||||
add_executable(build_tree build_tree.c)
|
||||
add_executable(hanota hanota.c)
|
||||
|
|
|
@ -19,7 +19,7 @@ typedef struct pair Pair;
|
|||
/* 链表节点 */
|
||||
struct node {
|
||||
Pair *pair;
|
||||
struct Node *next;
|
||||
struct node *next;
|
||||
};
|
||||
|
||||
typedef struct node Node;
|
||||
|
|
|
@ -16,7 +16,7 @@ void backtrack(vector<int> &state, const vector<int> &choices, vector<bool> &sel
|
|||
// 遍历所有选择
|
||||
for (int i = 0; i < choices.size(); i++) {
|
||||
int choice = choices[i];
|
||||
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素
|
||||
// 剪枝:不允许重复选择元素
|
||||
if (!selected[i]) {
|
||||
// 尝试:做出选择,更新状态
|
||||
selected[i] = true;
|
||||
|
|
|
@ -17,7 +17,7 @@ public class permutations_i {
|
|||
// 遍历所有选择
|
||||
for (int i = 0; i < choices.Length; i++) {
|
||||
int choice = choices[i];
|
||||
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素
|
||||
// 剪枝:不允许重复选择元素
|
||||
if (!selected[i]) {
|
||||
// 尝试:做出选择,更新状态
|
||||
selected[i] = true;
|
||||
|
|
|
@ -19,7 +19,7 @@ void backtrack(
|
|||
// 遍历所有选择
|
||||
for (int i = 0; i < choices.length; i++) {
|
||||
int choice = choices[i];
|
||||
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素
|
||||
// 剪枝:不允许重复选择元素
|
||||
if (!selected[i]) {
|
||||
// 尝试:做出选择,更新状态
|
||||
selected[i] = true;
|
||||
|
|
|
@ -14,7 +14,7 @@ func backtrackI(state *[]int, choices *[]int, selected *[]bool, res *[][]int) {
|
|||
// 遍历所有选择
|
||||
for i := 0; i < len(*choices); i++ {
|
||||
choice := (*choices)[i]
|
||||
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素
|
||||
// 剪枝:不允许重复选择元素
|
||||
if !(*selected)[i] {
|
||||
// 尝试:做出选择,更新状态
|
||||
(*selected)[i] = true
|
||||
|
|
|
@ -19,7 +19,7 @@ public class permutations_i {
|
|||
// 遍历所有选择
|
||||
for (int i = 0; i < choices.length; i++) {
|
||||
int choice = choices[i];
|
||||
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素
|
||||
// 剪枝:不允许重复选择元素
|
||||
if (!selected[i]) {
|
||||
// 尝试:做出选择,更新状态
|
||||
selected[i] = true;
|
||||
|
|
|
@ -13,7 +13,7 @@ function backtrack(state, choices, selected, res) {
|
|||
}
|
||||
// 遍历所有选择
|
||||
choices.forEach((choice, i) => {
|
||||
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素
|
||||
// 剪枝:不允许重复选择元素
|
||||
if (!selected[i]) {
|
||||
// 尝试:做出选择,更新状态
|
||||
selected[i] = true;
|
||||
|
|
|
@ -14,7 +14,7 @@ fn backtrack(mut state: Vec<i32>, choices: &[i32], selected: &mut [bool], res: &
|
|||
// 遍历所有选择
|
||||
for i in 0..choices.len() {
|
||||
let choice = choices[i];
|
||||
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素
|
||||
// 剪枝:不允许重复选择元素
|
||||
if !selected[i] {
|
||||
// 尝试:做出选择,更新状态
|
||||
selected[i] = true;
|
||||
|
|
|
@ -13,7 +13,7 @@ func backtrack(state: inout [Int], choices: [Int], selected: inout [Bool], res:
|
|||
}
|
||||
// 遍历所有选择
|
||||
for (i, choice) in choices.enumerated() {
|
||||
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素
|
||||
// 剪枝:不允许重复选择元素
|
||||
if !selected[i] {
|
||||
// 尝试:做出选择,更新状态
|
||||
selected[i] = true
|
||||
|
|
|
@ -18,7 +18,7 @@ function backtrack(
|
|||
}
|
||||
// 遍历所有选择
|
||||
choices.forEach((choice, i) => {
|
||||
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素
|
||||
// 剪枝:不允许重复选择元素
|
||||
if (!selected[i]) {
|
||||
// 尝试:做出选择,更新状态
|
||||
selected[i] = true;
|
||||
|
|
|
@ -223,7 +223,7 @@ $$
|
|||
=== "Go"
|
||||
|
||||
```go title="built_in_hash.go"
|
||||
|
||||
// Go 未提供内置 hash code 函数
|
||||
```
|
||||
|
||||
=== "Swift"
|
||||
|
|
Loading…
Reference in a new issue