Fix the codes of backtracking.
This commit is contained in:
parent
3d4fb3dbd7
commit
1600ed6dee
@ -15,15 +15,12 @@ public class preorder_find_nodes {
|
|||||||
if (root == null) {
|
if (root == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 尝试
|
|
||||||
if (root.val == 7) {
|
if (root.val == 7) {
|
||||||
// 记录解
|
// 记录解
|
||||||
res.add(root);
|
res.add(root);
|
||||||
}
|
}
|
||||||
preOrder(root.left);
|
preOrder(root.left);
|
||||||
preOrder(root.right);
|
preOrder(root.right);
|
||||||
// 回退
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -24,7 +24,6 @@ def pre_order(root: TreeNode) -> None:
|
|||||||
pre_order(root.right)
|
pre_order(root.right)
|
||||||
# 回退
|
# 回退
|
||||||
path.pop()
|
path.pop()
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
"""Driver Code"""
|
"""Driver Code"""
|
||||||
|
@ -23,7 +23,6 @@ def pre_order(root: TreeNode) -> None:
|
|||||||
pre_order(root.right)
|
pre_order(root.right)
|
||||||
# 回退
|
# 回退
|
||||||
path.pop()
|
path.pop()
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
"""Driver Code"""
|
"""Driver Code"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user