mirror of
https://github.com/krahets/hello-algo.git
synced 2026-09-03 21:57:14 +00:00
Update preorder_traversal_iii.
This commit is contained in:
@@ -42,7 +42,7 @@ enum PreorderTraversalIIICompact {
|
||||
res = []
|
||||
preOrder(root: root)
|
||||
|
||||
print("\n输出所有根节点到节点 7 的路径,路径中不包含值为 3 的节点,仅包含一个值为 7 的节点")
|
||||
print("\n输出所有根节点到节点 7 的路径,路径中不包含值为 3 的节点")
|
||||
for path in res {
|
||||
var vals: [Int] = []
|
||||
for node in path {
|
||||
|
||||
@@ -36,7 +36,6 @@ func backtrack(state: inout [TreeNode], choices: [TreeNode], res: inout [[TreeNo
|
||||
// 检查是否为解
|
||||
if isSolution(state: state) {
|
||||
recordSolution(state: state, res: &res)
|
||||
return
|
||||
}
|
||||
// 遍历所有选择
|
||||
for choice in choices {
|
||||
@@ -65,7 +64,7 @@ enum PreorderTraversalIIITemplate {
|
||||
var res: [[TreeNode]] = []
|
||||
backtrack(state: &state, choices: [root].compactMap { $0 }, res: &res)
|
||||
|
||||
print("\n输出所有根节点到节点 7 的路径,路径中不包含值为 3 的节点,仅包含一个值为 7 的节点")
|
||||
print("\n输出所有根节点到节点 7 的路径,路径中不包含值为 3 的节点")
|
||||
for path in res {
|
||||
var vals: [Int] = []
|
||||
for node in path {
|
||||
|
||||
Reference in New Issue
Block a user