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相关推荐

  1. 【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 ...

  2. 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 ...

  3. 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 ...

  4. 117. Populating Next Right Pointers in Each Node II 计算右边的附属节点

    [抄题]: Given a binary tree struct TreeLinkNode {TreeLinkNode *left;TreeLinkNode *right;TreeLinkNode * ...

  5. Populating Next Right Pointers in Each Node II

    Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. [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 ...

最新文章

  1. 深度学习之Pytorch基础教程!
  2. OpenCV与gcc和CMake一起使用
  3. mysql安装报错 1130_关于Linux编译安装会无法远程登录,报错:1130-host ... is not allowed to connect to this MySql server...
  4. HarmonyOS之基础环境和应用开发流程
  5. 求矩阵中各列数字的和 Exercise08_01
  6. 1103: 平均学分绩点(函数专题)
  7. spring boot配置logback日志
  8. 如何去掉自动弹出IE9介绍页
  9. 转载:Python正则表达式
  10. Ubuntu搜狗输入法乱码
  11. mapboxgl 互联网地图纠偏插件(三)
  12. 从入门到入土:Python实现爬取网易云歌词|评论生成词云图
  13. cim系统(cim系统包含哪些部分)
  14. 【音频系列】——MTK6735模块耳机通道外接功放的处理
  15. 2020年是走前端还是走后端好,前端又有哪些优势呢?
  16. Java Fork/Join与协程
  17. 有什么好的OCR软件可以实现图片转文字
  18. 全球及中国足病鞋垫行业销售情况及营销渠道策略报告(2022-2027年)
  19. 读 伯罗奔尼撒战争史
  20. 1251:丛林中的路

热门文章

  1. Linux基础第一章 概述
  2. vmware安装mac
  3. windows下怎么安装protobuf for python
  4. LVS DR模式 负载均衡服务搭建
  5. ora-12514报错解决方法
  6. CSS 多浏览器兼容又一方案
  7. WebSphere通过corba调Tuxedo问题(2)
  8. when will ifm open?
  9. 《技术的本质》2月24日part1
  10. 远程断开远程桌面会话之方法