【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 ...
随机推荐
- 一些常用运行命令和CMD命令
运行命令 1. 进入服务页面的命令: services.msc 2. 远程连接命令:mstsc.exe 3. 配置电脑启动项 msconfig 4. 计算器 calc.exe 5. 设定关机时间(se ...
- ID(dfs+bfs)-hdu-4127-Flood-it!
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4127 题目意思: 给n*n的方格,每个格子有一种颜色(0~5),每次可以选择一种颜色,使得和左上角相 ...
- ES6的模块化
在之前的 javascript 中一直是没有模块系统的,前辈们为了解决这些问题,提出了各种规范, 最主要的有CommonJS和AMD两种.前者用于服务器,后者用于浏览器.而 ES6 中提供了简单的模块 ...
- Android平台抓取native crash log
Android开发中,在Java层可以方便的捕获crashlog,但对于 Native 层的 crashlog 通常无法直接获取,只能通过系统的logcat来分析crash日志. 做过 Linux 和 ...
- Android studio教程:[4]真机测试
有了Android studio这么好用的软件,自然要有一部不错的安卓手机,然后在真机上测试自己的程序,那样才能更好的发现程序中存在的问题,毕竟模拟器不是真正的手机嘛. 工具/原料 Android s ...
- error LNK2019: 无法解析的外部符号 "public:
错误 1 error LNK2019: 无法解析的外部符号 "public: __thiscall test::test(void)" (??0test@@QAE@XZ),该符号在 ...
- C#传递参数大集合
方法的参数是个值得特别注意的地方.方法的参数传递有四种类型:传值(by value),传址(by reference),输出参数(by output),数组参数(by array).传值参数无需额外的 ...
- js 数组排除重复值(string)
前提:数组中的元素类型为:string 在网上看了许多高大尚的文章,还是解决不了我的string arry 的问题,只能怪自己脑残了,上代码: <!DOCTYPE html> <ht ...
- atoi atol strtod strtol strtoul _gcvt
如果以下函数,您在使用的时候,总是输出一个莫名的值,是因为您忘记了引用头文件 #include <stdlib.h> 1- atoi int atoi(const char *nptr); ...
- [XMPP]简易的聊天室实现[一]
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...