Populating Next Right Pointers in Each Node I or II
Follow up for problem "Populating Next Right Pointers in Each Node".
What if the given tree could be any binary tree? Would your previous solution still work?
Note:
- You may only use constant extra space.
For example,
Given the following binary tree,
1/ \2 3/ \ \4 5 7
After calling your function, the tree should look like:
1 -> NULL/ \2 -> 3 -> NULL/ \ \4-> 5 -> 7 -> NULL
我以前为啥要做那么复杂呢
ref http://www.cnblogs.com/springfor/p/3889327.html
关键在于找到有效的下家P
public void connect(TreeLinkNode root) { if (root == null) return; TreeLinkNode p = root.next; while(p!=null){if(p.left!=null){p = p.left;break;}if(p.right!=null){p = p.right;break;}p = p.next;}if(root.right!=null)root.right.next = p;if(root.left!=null){if(root.right!=null){root.left.next = root.right;}elseroot.left.next =p;}connect(root.right);connect(root.left);}
转载于:https://www.cnblogs.com/jiajiaxingxing/p/4565358.html
Populating Next Right Pointers in Each Node I or II相关推荐
- Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...
- Leetcode: Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree ...
- leetcode - Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...
- LeetCode 117. Populating Next Right Pointers in Each Node II
原题链接在这里:https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/ 题目: Given a bi ...
- 117. Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...
- LeetCode OJ - Populating Next Right Pointers in Each Node II
题目: Follow up for problem "Populating Next Right Pointers in Each Node". What if the given ...
- [Leetcode Week15]Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each Node 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/populati ...
- Leetcode 笔记 116 - Populating Next Right Pointers in Each Node
题目链接:Populating Next Right Pointers in Each Node | LeetCode OJ Given a binary tree struct TreeLinkNo ...
- [Leetcode][JAVA] Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...
最新文章
- 隐藏画质代码_如何让千元机高画质满帧吃鸡?最全教程奉上!
- python读取excel日期内容读出来是数字-Python xlrd读取excel日期类型的2种方法
- RAMdisk保存文件方案,解决关机后无盘镜像文件没了的方案
- 深大教授开源的人脸检测库,速度号称史上最快
- 等于x分之a的平方的导数_清华学霸丨手把手教你导数大题如何骗分(文理通用),家长为孩子收...
- html鼠标悬停效果_【开发小技巧】023—如何使用HTML和CSS实现3D文字效果
- 视觉SLAM十四讲学习笔记---前三讲学习笔记总结之SLAM的作用、变换和位姿表示
- 【华为云技术分享】玩转云上数据湖,解析Serverless 技术落地
- 电子信息计算机调剂到能源动力,江苏科技大学机械、电子信息、电子信息能源动力、土木水利2020年考研调剂信息...
- 西门子1500和300哪个贵_西门子PLC S7-300和1500之间的通信资源管理之比较?
- PS光效插件 DFT 1.1.1.3汉化破解版,比灯光工厂更强大支持PSCC2019
- Reeder for Chrome:让 Google Reader 更加简洁美观
- NTC热敏电阻温度计算方法,Steinhart-Hart方程和B值法
- 老人为戒烟嗑瓜子 脚趾腐烂散发难闻臭味令孙儿恶心至极
- C# 读写xml、excel、word、ppt、access
- wpf label下划线不显示的问题
- 服务器将系统盘,如何将Windows服务器系统的inetpub目录移到其它盘
- STM32编程环境配置(kile5)
- Android 按钮实现按压水波纹效果
- javaWeb核心技术第六篇之BootStrap