117. Populating Next Right Pointers in Each Node 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
题目含义:从左到右连接每一层的节点
1 public void connect(TreeLinkNode root) { 2 while(root != null){ 3 TreeLinkNode tempChild = new TreeLinkNode(0); 4 TreeLinkNode currentChild = tempChild; 5 while(root!=null){ 6 if(root.left != null) { currentChild.next = root.left; currentChild = currentChild.next;} 7 if(root.right != null) { currentChild.next = root.right; currentChild = currentChild.next;} 8 root = root.next; 9 } 10 root = tempChild.next; 11 } 12 }
转载于:https://www.cnblogs.com/wzj4858/p/7715047.html
117. Populating Next Right Pointers in Each Node II相关推荐
- 【To Understand!】LeetCode 117. Populating Next Right Pointers in Each Node II
LeetCode 117. Populating Next Right Pointers in Each Node II Solution1:我的答案 层次遍历 /*** Definition for ...
- 117 Populating Next Right Pointers in Each Node II
117 Populating Next Right Pointers in Each Node II 就是 Bibary Tree Level order Traverse class Solutio ...
- 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 计算右边的附属节点
[抄题]: Given a binary tree struct TreeLinkNode {TreeLinkNode *left;TreeLinkNode *right;TreeLinkNode * ...
- 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 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][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 ...
最新文章
- 深度学习之Pytorch基础教程!
- OpenCV与gcc和CMake一起使用
- mysql安装报错 1130_关于Linux编译安装会无法远程登录,报错:1130-host ... is not allowed to connect to this MySql server...
- HarmonyOS之基础环境和应用开发流程
- 求矩阵中各列数字的和 Exercise08_01
- 1103: 平均学分绩点(函数专题)
- spring boot配置logback日志
- 如何去掉自动弹出IE9介绍页
- 转载:Python正则表达式
- Ubuntu搜狗输入法乱码
- mapboxgl 互联网地图纠偏插件(三)
- 从入门到入土:Python实现爬取网易云歌词|评论生成词云图
- cim系统(cim系统包含哪些部分)
- 【音频系列】——MTK6735模块耳机通道外接功放的处理
- 2020年是走前端还是走后端好,前端又有哪些优势呢?
- Java Fork/Join与协程
- 有什么好的OCR软件可以实现图片转文字
- 全球及中国足病鞋垫行业销售情况及营销渠道策略报告(2022-2027年)
- 读 伯罗奔尼撒战争史
- 1251:丛林中的路