二叉树-populate next node
来源:互联网 发布:java 首字母小写 编辑:程序博客网 时间:2024/05/21 18:40
2014.8.17 update:
可以利用linkelist里面fake node的思想来链接下一层node:
public void connect(TreeLinkNode root) { if (root == null) { return; } TreeLinkNode cur = root; while(cur != null) { TreeLinkNode nextHead = new TreeLinkNode(0); TreeLinkNode nextCur = nextHead; while (cur != null) { if (cur.left != null) { nextCur.next = cur.left; nextCur = nextCur.next; } if (cur.right != null) { nextCur.next = cur.right; nextCur = nextCur.next; } cur = cur.next; } cur = nextHead.next; }
// populating next node when tree is balanced
public class Solution {
}
// unbalanced tree populating next node
public class Solution {
}
0 0
- 二叉树-populate next node
- Populate Next Right Pointer in Each Node
- populate next right pointer in each node
- 二叉树中增加next指针 Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node 完美二叉树添加next指针 @LeetCode
- 116.Populating Next Right Pointers in Each Node(二叉完全树的next结点)
- [Leetcode] Populating Next Right Pointers in Each Node 二叉树Next指针
- Populating Next Right Pointers in Each Node II 任意(非完美)二叉树添加next指针 @LeetCode
- Leetcode 116 Populating Next Right Pointers in Each Node 二叉树填充next指针指向右侧结点
- Leetcode 117 Populating Next Right Pointers in Each Node II 二叉树填充next指针指向右侧结点 II
- Populating Next Right Pointers in Each Node II 顺序链接二叉树每一层结点
- Populating Next Right Pointers in Each Node 连接二叉树每一层的结点
- 【二叉树&层次遍历】Populating Next Right Pointers in Each Node
- 【二叉树&层次遍历】Populating Next Right Pointers in Each Node II
- [C++]LeetCode: 123 Populating Next Right Pointers in Each Node(链接完全二叉树)
- [C++]LeetCode: 124 Populating Next Right Pointers in Each Node II(链接二叉树)
- 【LeetCode】 Populating Next Right Pointers in Each Node 完全二叉树
- leetcode---Populating Next Right Pointers in Each Node---二叉树、广搜
- 二叉树求大和最小depth
- 经验总结25--释放内存的重要性
- 二叉树-对称树
- ibm的InfoSphere Streams的制备技术指南精通测试V1
- 二叉树-preorder+inorder 与& postorder+inorder
- 二叉树-populate next node
- 二叉树-flatten binary search tree to linked lis
- 二叉树-Convert Sorted List to Binary Search Tree
- Human Gene Functions - POJ 1080 UVaLive 2344 dp
- 二叉树-recover binary search tree
- 罗马数字转化
- Letter combinations of phone number
- sudoku
- word search