Populating Next Right Pointers in Each Node
来源:互联网 发布:人工智能 图书馆 编辑:程序博客网 时间:2024/06/06 16:53
1.题目
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
.
Initially, all next pointers are set to NULL
.
2.算法
public void connect(TreeLinkNode root) { if(root == null) return; TreeLinkNode lastHead = root; TreeLinkNode current = null; TreeLinkNode curHead = null; while(lastHead!=null) { TreeLinkNode lastCur = lastHead; while(lastCur != null) { if(lastCur.left!=null) { if(curHead == null) { curHead = lastCur.left; current = curHead; } else { current.next = lastCur.left; current = current.next; } } if(lastCur.right!=null) { if(curHead == null) { curHead = lastCur.right; current = curHead; } else { current.next = lastCur.right; current = current.next; } } lastCur = lastCur.next; } lastHead = curHead; curHead = null; } }
0 0
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- Populating Next Right Pointers in Each Node
- spring 4.3.5导入commons-logging的jar包后报NoClassDefFoundError
- 【ife】任务二十五:JavaScript和树(四)
- 分区表 主键全局索引和分区索引区别
- linux服务器ssh、公匙和密钥实战详解
- JavaScript组件设计思想(二)
- Populating Next Right Pointers in Each Node
- Powershell命令杂记
- //编写函数fun,其功能是将字符串末尾的*号删掉。如:******ABC*D*B*BDD***** //删掉之后:******ABC*D*B*BDD
- 王爽汇编语言课程设计1
- Caffe Blob Dtype理解
- list.add(rs.getInt())报错的问题
- 【网络流24题】1.飞行员配对方案问题
- Android中双击图片放大 PhotoView
- Codeforces 160E