Populating Next Right Pointers in Each Node II
来源:互联网 发布:python字符串转换列表 编辑:程序博客网 时间:2024/06/10 14:18
public void connect(TreeLinkNode root) { // Start typing your Java solution below // DO NOT write main() function while(root != null) { TreeLinkNode tmp = root; while(tmp != null) { if(tmp.left != null || tmp.right != null) { TreeLinkNode uncle = tmp; while(uncle.next != null && uncle.next.left == null && uncle.next.right == null) { uncle = uncle.next; } TreeLinkNode next = null; if(uncle.next != null) next = (uncle.next.left == null) ? uncle.next.right : uncle.next.left; if(tmp.left != null) tmp.left.next = (tmp.right == null) ? next : tmp.right; if(tmp.right != null) tmp.right.next = next; } tmp = tmp.next; } while(root.next != null && root.left == null && root.right == null) { root = root.next; } root = (root.left == null) ? root.right : root.left; } }
- Populating Next Right Pointers in Each Node、Populating Next Right Pointers in Each Node II
- 【LeetCode】Populating Next Right Pointers in Each Node 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 II
- [LeetCode] Populating Next Right Pointers in Each Node II
- leetcode 79: 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 II
- 【leetcode】Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node II
- [Leetcode]Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node II
- Populating Next Right Pointers in Each Node (I & II)
- Populating Next Right Pointers in Each Node II
- 尚学堂马士兵servlet/JSP笔记(二、servlet)
- Unity3D 录音功能 音频保存
- 结构体之间的强制类型转换
- 黑马程序员java学习日记十三 Java 类加载器
- 02-使用sendframework打印出数据库数据
- Populating Next Right Pointers in Each Node II
- C语言运算符优先级 详细列表
- <<C++ design patterns and Derivatives Pricing>> 学习系列 CH1-对蒙特卡洛基本理解
- 黑马程序员java学习日记十四 代理类的作用和原理以及APO概念
- 尚学堂马士兵servlet/JSP笔记(三、Cookie、Session、Application和数据库处理)
- b3log的计时器的应用
- shell 编程学习笔记(二)
- 数据库指南-SQL与NoSQL
- Path Sum