题目:Populating Next Right Pointers in Each Node

<span style="font-size:18px;">/*
* LeetCode Populating Next Right Pointers in Each Node
* 题目:为树的每一个节点添加一个next指针。指向树状结构排列时自己的右边节点,假设右边没有节点则置为null
* * Definition for binary tree with next pointer.
* public class TreeLinkNode {
* int val;
* TreeLinkNode left, right, next;
* TreeLinkNode(int x) { val = x; }
* }
*/
package javaTrain; public class Train10 {
public void connect(TreeLinkNode root) {
if(root == null) return;
root.next = null;
connectHelp(root.left,root.right);
}
private void connectHelp(TreeLinkNode left,TreeLinkNode right){
if(left == null && right == null) return;
if(right == null) left.next = null;
else left.next = right;
connectHelp(left.left,left.right);
connectHelp(left.right,right.left);
connectHelp(right.left,right.right);
}
}
</span>

【LeetCode】 Populating Next Right Pointers in Each Node 全然二叉树的更多相关文章

  1. LeetCode:Populating Next Right Pointers in Each Node I II

    LeetCode:Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeL ...

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

  3. [LeetCode] Populating Next Right Pointers in Each Node 每个节点的右向指针

    Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...

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

  5. [leetcode]Populating Next Right Pointers in Each Node II @ Python

    原题地址:https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/ 题意: Follow up ...

  6. LeetCode: Populating Next Right Pointers in Each Node II 解题报告

    Populating Next Right Pointers in Each Node IIFollow up for problem "Populating Next Right Poin ...

  7. LEETCODE —— Populating Next Right Pointers in Each Node

    Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeLinkNode * ...

  8. LeetCode - 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: Populating Next Right Pointers in Each Node 解题报告

    Populating Next Right Pointers in Each Node TotalGiven a binary tree struct TreeLinkNode {      Tree ...

随机推荐

  1. 各硬件装置在 Linux 中的文件名(笔记)

    各硬件装置在 Linux 中的文件名

  2. 谋哥:研究App排行榜浮出的神器

    昨天发的<App排行榜的秘密>到头条网,阅读量到2万,踩的比顶的多几倍.原因是由于我使用360市场的数据来分析,而且这帮喷子根本不看你分析数据背后的意义,反正看到自己不喜欢的比方" ...

  3. 走进C++程序世界------继承和派生

    继承和派生 继承是面向对象编程语言的最重要方面之一,正确的使用继承可编写出设计良好,容易于维护和扩展的应用程序.下面是在其他博客中的总结: ****************************** ...

  4. Unity 3D 调用摄像头捕获照片 录像

    1,要想调用摄像头首先要打开摄像头驱动,如果用户允许则可以使用. 2,定义WebCamTexture的变量用于捕获单张照片. 3,连续捕获须启用线程. 实现代码: using UnityEngine; ...

  5. Mysql的安装(二进制免编译包) 5.1版本

    一,Mysql的安装: 1.下载mysql,可以通过http://mirrors.sohu.com/下载mysql软件. wget http://mirrors.sohu.com/mysql/MySQ ...

  6. Convert Sorted List to Binary Search Tree java

    public TreeNode sortedListToBST(ListNode head) { if(head==null) return new TreeNode(0); ArrayList< ...

  7. Spring-----6、Spring3.0提供的Java配置管理

    转载自:http://blog.csdn.net/hekewangzi/article/details/45646279

  8. UVALive 6959 - Judging Troubles

    给两组字符串,最多有多少对相同. map做映射判断一下. #include <iostream> #include <cstdio> #include <map> ...

  9. TCP/IP详解之:SNMP

    基于TCP/IP的网络管理包含3个组成部分: 一个管理信息库MIB:MIB包含所有代理进程的所有可被查询和修改的参数 关于MIB的一套公用的结构和表示符号,即SMI(管理信息结构) 管理进程和代理进程 ...

  10. Android url中文编码问题

    最近项目遇见一个很奇葩问题,关于URL问题,项目中加载图片,图片的URL含有中文,但是,我的手机可以加载,没问题,同事也都可以,但是测试手机却不可以,加载失败,找到问题,就是URL含有中文问题. 解决 ...