mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 23:16:28 +08:00
build
This commit is contained in:
parent
4eb7734fa9
commit
7645bf97df
3 changed files with 20 additions and 2 deletions
|
@ -502,6 +502,7 @@ def backtrack(state, choices, res):
|
|||
if (isValid(state, choice)) {
|
||||
// 尝试:做出选择,更新状态
|
||||
makeChoice(state, choice);
|
||||
// 进行下一轮选择
|
||||
backtrack(state, Arrays.asList(choice.left, choice.right), res);
|
||||
// 回退:撤销选择,恢复到之前的状态
|
||||
undoChoice(state, choice);
|
||||
|
@ -552,6 +553,7 @@ def backtrack(state, choices, res):
|
|||
if (isValid(state, choice)) {
|
||||
// 尝试:做出选择,更新状态
|
||||
makeChoice(state, choice);
|
||||
// 进行下一轮选择
|
||||
vector<TreeNode *> nextChoices{choice->left, choice->right};
|
||||
backtrack(state, nextChoices, res);
|
||||
// 回退:撤销选择,恢复到之前的状态
|
||||
|
@ -597,6 +599,7 @@ def backtrack(state, choices, res):
|
|||
if is_valid(state, choice):
|
||||
# 尝试:做出选择,更新状态
|
||||
make_choice(state, choice)
|
||||
# 进行下一轮选择
|
||||
backtrack(state, [choice.left, choice.right], res)
|
||||
# 回退:撤销选择,恢复到之前的状态
|
||||
undo_choice(state, choice)
|
||||
|
@ -708,8 +711,8 @@ def backtrack(state, choices, res):
|
|||
if (isValid(state, choice)) {
|
||||
// 尝试:做出选择,更新状态
|
||||
makeChoice(state, choice);
|
||||
List<TreeNode> nextChoices = new List<TreeNode>() { choice.left, choice.right };
|
||||
backtrack(state, nextChoices, res);
|
||||
// 进行下一轮选择
|
||||
backtrack(state, new List<TreeNode> { choice.left, choice.right }, res);
|
||||
// 回退:撤销选择,恢复到之前的状态
|
||||
undoChoice(state, choice);
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ comments: true
|
|||
// 尝试:做出选择,更新状态
|
||||
selected[i] = true;
|
||||
state.add(choice);
|
||||
// 进行下一轮选择
|
||||
backtrack(state, choices, selected, res);
|
||||
// 回退:撤销选择,恢复到之前的状态
|
||||
selected[i] = false;
|
||||
|
@ -86,6 +87,7 @@ comments: true
|
|||
// 尝试:做出选择,更新状态
|
||||
selected[i] = true;
|
||||
state.push_back(choice);
|
||||
// 进行下一轮选择
|
||||
backtrack(state, choices, selected, res);
|
||||
// 回退:撤销选择,恢复到之前的状态
|
||||
selected[i] = false;
|
||||
|
@ -122,6 +124,7 @@ comments: true
|
|||
# 尝试:做出选择,更新状态
|
||||
selected[i] = True
|
||||
state.append(choice)
|
||||
# 进行下一轮选择
|
||||
backtrack(state, choices, selected, res)
|
||||
# 回退:撤销选择,恢复到之前的状态
|
||||
selected[i] = False
|
||||
|
@ -184,6 +187,7 @@ comments: true
|
|||
// 尝试:做出选择,更新状态
|
||||
selected[i] = true;
|
||||
state.Add(choice);
|
||||
// 进行下一轮选择
|
||||
backtrack(state, choices, selected, res);
|
||||
// 回退:撤销选择,恢复到之前的状态
|
||||
selected[i] = false;
|
||||
|
@ -264,6 +268,7 @@ comments: true
|
|||
duplicated.add(choice); // 记录选择过的元素值
|
||||
selected[i] = true;
|
||||
state.add(choice);
|
||||
// 进行下一轮选择
|
||||
backtrack(state, choices, selected, res);
|
||||
// 回退:撤销选择,恢复到之前的状态
|
||||
selected[i] = false;
|
||||
|
@ -300,6 +305,7 @@ comments: true
|
|||
duplicated.emplace(choice); // 记录选择过的元素值
|
||||
selected[i] = true;
|
||||
state.push_back(choice);
|
||||
// 进行下一轮选择
|
||||
backtrack(state, choices, selected, res);
|
||||
// 回退:撤销选择,恢复到之前的状态
|
||||
selected[i] = false;
|
||||
|
@ -338,6 +344,7 @@ comments: true
|
|||
duplicated.add(choice) # 记录选择过的元素值
|
||||
selected[i] = True
|
||||
state.append(choice)
|
||||
# 进行下一轮选择
|
||||
backtrack(state, choices, selected, res)
|
||||
# 回退:撤销选择,恢复到之前的状态
|
||||
selected[i] = False
|
||||
|
@ -402,6 +409,7 @@ comments: true
|
|||
duplicated.Add(choice); // 记录选择过的元素值
|
||||
selected[i] = true;
|
||||
state.Add(choice);
|
||||
// 进行下一轮选择
|
||||
backtrack(state, choices, selected, res);
|
||||
// 回退:撤销选择,恢复到之前的状态
|
||||
selected[i] = false;
|
||||
|
|
|
@ -202,6 +202,13 @@ comments: true
|
|||
=== "C"
|
||||
|
||||
```c title="quick_sort.c"
|
||||
/* 元素交换 */
|
||||
void swap(int nums[], int i, int j) {
|
||||
int tmp = nums[i];
|
||||
nums[i] = nums[j];
|
||||
nums[j] = tmp;
|
||||
}
|
||||
|
||||
/* 快速排序类 */
|
||||
// 快速排序类-哨兵划分
|
||||
int partition(int nums[], int left, int right) {
|
||||
|
|
Loading…
Reference in a new issue