# Middle-题目17：116. Populating Next Right Pointers in Each Node

Given a binary tree

struct TreeLinkNode {
}


Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
For example,
Given the following perfect binary tree,

         1
/  \
2    3
/ \  / \
4  5  6  7

After calling your function, the tree should look like:

         1 -> NULL
/  \
2 -> 3 -> NULL
/ \  / \
4->5->6->7 -> NULL

public class Solution {
public void connect(TreeLinkNode root) {
if(root==null)
return;
else if(root.left == null && root.right == null && root.next == null) { // root is a leaf node
root.next=null;
return;
}
else {
if(root.left != null)
root.left.next = root.right;
if(root.right != null && root.next != null)
root.right.next = root.next.left;
if(root.right != null && root.next == null)
root.right.next = null;
connect(root.left);
connect(root.right);
}
}
}

0ms，beats 81.60%，众数1ms，52.14%

#### 【LeetCode-面试算法经典-Java实现】【116-Populating Next Right Pointers in Each Node（二叉树链接右指针）】

2015-08-12 06:30:46

#### LeetCode 116 Populating Next Right Pointers in Each Node 解题报告

2015-03-30 20:44:13

#### Populating Next Right Pointers in Each Node -- LeetCode

2014-04-12 03:11:29

#### Leetcode_116_Populating Next Right Pointers in Each Node

2015-02-05 19:18:29

#### 117. Populating Next Right Pointers in Each Node II Leetcode Python

2015-01-26 10:16:40

#### [LeetCode]Populating Next Right Pointers in Each Node II, 解题报告

2013-12-19 11:17:47

#### Populating Next Right Pointers in Each Node II 任意（非完美）二叉树添加next指针 @LeetCode

2013-11-21 04:45:02

#### LeetCode 117:Populating Next Right Pointers in Each Node II

2015-12-31 00:43:12

#### LeetCode题解：Populating Next Right Pointers in Each Node

2015-10-02 21:01:47

#### Populating Next Right Pointers in Each Node II -- LeetCode

2014-04-13 09:09:24