题目: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. [转]Activemq管理和基本介绍

    1.ActiveMQ服务器工作模型       通过ActiveMQ消息服务交换消息.消息生产者将消息发送至消息服务,消息消费者则从消息服务接收这些消息.这些消息传送操作是使用一组实现 ActiveM ...

  2. hdu 5495 LCS

    Problem Description You are given two sequence {a1,a2,...,an} and {b1,b2,...,bn}. Both sequences are ...

  3. IOS反地理编码取得城市名称

    // 获取当前所在的城市名 CLGeocoder *reverseGeocoder=[[CLGeocoder alloc] init]; [reverseGeocoder reverseGeocode ...

  4. vs debug 快捷键

    命令名 快捷键 说明 调试.应用代码更改 Alt + F10 启动生成操作,利用它可以通过“编辑并继续”功能应用对正在调试的代码所作的更改. 调试.自动窗口 Ctrl + D,Ctrl + A 显示“ ...

  5. AngularJS 的一些坑

    UI的闪烁 Angular的自动数据绑定功能是亮点,然而,他的另一面是:在Angular初始化之前,页面中可能会给用户呈现出没有解析的表达式.当DOM准备就绪,Angular计算并替换相应的值.这样就 ...

  6. Ext布局

    Ext主要包括11种标准布局方式:Auto(自动布局).CheckboxGroup(复选框组布局).Fit(自适应布局).Column(列布局).Accordion(折叠布局).Table(表格布局) ...

  7. Android studio教程:[3]修改背景主题

    android studio开发环境的背景主题是可以更改的,现在都流行黑色背景,这样让软件显得更高端大气的,更加赏心悦目,但最主要的还是看起来更舒适更顺眼.下面就教大家如何更改背景主题. 工具/原料 ...

  8. JQ 复制节点

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. 浅说CPU并行计算与GPU并行计算

    最近在学一门课,叫做“C++与并行计算”.要用到多CPU(进程)并行的原理,实现语言是C++的MPI接口.联想到上学期用到CUDA C/C++来做并行计算,就对这两门语言做一个总结,分享下自己关于并行 ...

  10. MyBatis 注解

    注解 目标 相对应的 XML 描述 @CacheNamespace 类 <cache> 为给定的命名空间 (比如类) 配置缓存. 属性:implemetation,eviction, fl ...