讨论/《二叉树》 - 填充每个节点的下一个右侧节点指针 II/
《二叉树》 - 填充每个节点的下一个右侧节点指针 II

JS(写法):
var connect = function(root) {
if(root != null){
find(root);
}
return root;
};
function find(n){
if(n == null){
return;
}
if(n.left != null){
if(n.right != null){
n.left.next = n.right;
}else{
n.left.next = getNext(n.next);
}
}
if(n.right != null){
n.right.next = getNext(n.next);
}
find(n.right);
find(n.left);
}
function getNext(uncle){
if(uncle == null)return null;
if(uncle.left != null){return uncle.left;}
if(uncle.right != null){return uncle.right;}
return getNext(uncle.next);
}

展开全部 12 讨论