【LeetCode】 Populating Next Right Pointers in Each Node 全然二叉树
题目: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 全然二叉树的更多相关文章
- 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 ...
- [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] Populating Next Right Pointers in Each Node 每个节点的右向指针
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...
- 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]Populating Next Right Pointers in Each Node II @ Python
原题地址:https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/ 题意: Follow up ...
- LeetCode: Populating Next Right Pointers in Each Node II 解题报告
Populating Next Right Pointers in Each Node IIFollow up for problem "Populating Next Right Poin ...
- LEETCODE —— Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeLinkNode * ...
- LeetCode - Populating Next Right Pointers in Each Node II
题目: Follow up for problem "Populating Next Right Pointers in Each Node". What if the given ...
- LeetCode: Populating Next Right Pointers in Each Node 解题报告
Populating Next Right Pointers in Each Node TotalGiven a binary tree struct TreeLinkNode { Tree ...
随机推荐
- 上传form表单
<form name="theForm" method="post" action="index.php?m=back&c=Goods& ...
- Easy Number Challenge(暴力,求因子个数)
Easy Number Challenge Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- ExtJS+ASP.NET自己定义曲线
第一步:创建Store数据源 var myData = []; myData.push({ 'name': '1', 'Oil_Production': '30', 'Water_Injection' ...
- 【类似N^N做法的斐波那契数列】【HDU1568】 Fibonacci
Fibonacci Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- jsp页面使用jstl标签格式化String类型日期
1.引入jstl <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> ...
- font-face 使用
<style type="text/css"> @font-face{ font-family:'Aaargh'; src:url(fonts/Aaargh/Aaarg ...
- Lowest Common Ancestor of a Binary Search Tree、Lowest Common Ancestor of a Binary Search Tree
1.Lowest Common Ancestor of a Binary Search Tree Total Accepted: 42225 Total Submissions: 111243 Dif ...
- kettle查询出来的真实值被识别为null
问题描述: 通过关联表查询出来的applyId(申请编号),在数据流里也是能看到的,但是在写入到数据表中的时候,由于设置了这个字段不能为空,所以一直报错. 问题实质: 数据流内存在的数据却不能保存,原 ...
- Git使用笔记(一)
今天第一次使用Git,在本地和CSDN Code进行代码同步.鉴于“好记性不如烂笔头”的经验教训,特把步骤记录下来. 准备工作: 1. 在CSDN(或者Github)上注册一个帐号,然后创建一个Rep ...
- 工作中使用seajs后的一些总结
工作中用seajs一段时间了,小小地总结一下. 使用seajs五部曲: 1.布置你项目的目录结构 2.设置seajs的config项,我一般是单独一个js文件--> seajs-config.j ...