做完上一题发现这一题只是把完美二叉树改成了普通二叉树。
思路和解法完全不变,连代码都一样。
private final Stack
<Node> stack
= new Stack<>();
public Node
connect(Node root
) {
if (root
== null
)
return null
;
root
.next
= stack
.isEmpty() ? null
: stack
.pop();
connect(root
.right
);
connect(root
.left
);
stack
.push(root
);
return root
;
}
转载请注明原文地址: https://lol.8miu.com/read-29256.html