题目: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. 逐渐深入地理解Ajax

    Ajax的基本原理是:XMLHttpRequest对象(简称XHR对象),XHR为向服务器发送请求和解析服务器响应提供了流畅的接口.能够以异步方式从服务器获得更多信息.意味着用户不必刷新页面也能取得新 ...

  2. myeclipse集成weblogicserver

    今天为了学一下JMS的东东, 不得不安装个weblogicserver, 下面是详细的安装步骤: 1. 首先去官网下载一个weblogic: 下载地址: http://download.oracle. ...

  3. UNIX环境高级编程--高级I/O(三)

    一.高级I/O 包括非阻塞I/O.记录锁.系统V流机制.I/O多路回转(select和poll函数).readv和writev函数以及存储映射I/O(mmap),这些都是高级I/O.    其实在上面 ...

  4. 【Samza系列】实时计算Samza中文教程(二)——概念

    希望上一篇背景篇让大家对流式计算有了宏观的认识,本篇依据官网是介绍概念,先让我们看看有哪些东西呢?     概念一:Streams     Samza是处理流的.流则是由一系列不可变的一种相似类型的消 ...

  5. SSH框架-unexpected token: * near line 1, column 8 [select * from tb_chaper where course_id = 2];报错解决方法

    SSH项目,访问jsp页面出现报错,控制台显示报错信息: org.springframework.orm.hibernate3.HibernateQueryException: unexpected ...

  6. 80端口被NT kernel & System 占用pid= 4的解决方法

    引用http://www.2cto.com/os/201111/111269.html的方法.亲测可用 该进程是Http.sys.它是http API的驱动组件,Http栈服务器.如果该端口被Http ...

  7. O the joy of having nothing / 아무것도 갖지않고

    Chords: C G Am Em F C Dm G C G Am Em F C Am Dm G English - O the joy of having nothing and being not ...

  8. dojo.create\dojo.place\dojo.empty\dojo.destroy\dojo.body

    1.dojo.create 1.create a node; 2.set attributes on it;  3.place it in the DOM. dojo.create(/*String| ...

  9. MVC中的错误过滤器无法拦截URL路径错误的解决办法

    “/”应用程序中的服务器错误. 无法找到资源. 说明: HTTP 404.您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用.请检查以下 URL 并确保其拼写正确. 请求 ...

  10. java之集合类框架的简要知识点:泛型的类型擦除

    这里想说一下在集合框架前需要理解的小知识点,也是个人的肤浅理解,不知道理解的正不正确,请大家多多指教.这里必须谈一下java的泛型,因为它们联系紧密,我们先看一下这几行代码: Class c1 = n ...