leetcode:Populating Next Right Pointers in Each Node
2014-06-15 14:59
169 查看
显然可以知道,一个节点的left节点的next指向节点right节点,right节点指向该节点next节点的left节点
/**
* Definition for binary tree with next pointer.
* public class TreeLinkNode {
* int val;
* TreeLinkNode left, right, next;
* TreeLinkNode(int x) { val = x; }
* }
*/
public class Solution {
public void connect(TreeLinkNode root) {
if(root == null){
return ;
}
else{
if(root.left != null){
root.left.next = root.right;
}
if(root.right != null){
root.right.next = (root.next == null ? null : root.next.left);
}
connect(root.left);
connect(root.right);
}
}
}
相关文章推荐
- [LeetCode] Populating Next Right Pointers in Each Node
- [Leetcode] Populating Next Right Pointers in Each Node
- [Leetcode] Populating Next Right Pointers in Each Node ii
- LeetCode: Populating Next Right Pointers in Each Node
- 【leetcode】Populating Next Right Pointers in Each Node II
- LeetCode Populating Next Right Pointers in Each Node
- LeetCode - Populating Next Right Pointers in Each Node
- Leetcode: Populating Next Right Pointers in Each Node
- leetcode 79: Populating Next Right Pointers in Each Node II
- LeetCode: Populating Next Right Pointers in Each Node
- [LeetCode] Populating Next Right Pointers in Each Node
- LeetCode(Oct28'12):Populating Next Right Pointers in Each Node II
- [LeetCode]Populating Next Right Pointers in Each Node
- leetcode 78: Populating Next Right Pointers in Each Node
- [LeetCode] Populating Next Right Pointers in Each Node II
- [LeetCode] Populating Next Right Pointers in Each Node II 解题报告
- 【leetcode】 Populating Next Right Pointers in Each Node
- leetcode Populating Next Right Pointers in Each Node II
- [Leetcode]Populating Next Right Pointers in Each Node II
- leetcode 79: Populating Next Right Pointers in Each Node II