3月3日[Go_deep]Populating Next Right Pointers in Each Node
原题:Populating Next Right Pointers in Each Node
简单的链表二叉树增加Next节点信息,没什么坑。不过还是WA了两次,还是有点菜,继续做,另外leetcode一共150题,考虑两周做完吧,要加速了。
注意:看清楚左右和递归,像标题说的,Go_deep吧。
/**
* Definition for binary tree with next pointer.
* struct TreeLinkNode {
* int val;
* TreeLinkNode *left, *right, *next;
* TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {}
* };
*/
class Solution {
public:
void connect(TreeLinkNode *root) {
if (root == NULL) return; if (root->left != NULL)
{
root->left->next = root->right; TreeLinkNode *go_deep_left = root->left->right;
TreeLinkNode *go_deep_right = (root->right != NULL)?(root->right->left):NULL; while (go_deep_left != NULL && go_deep_right != NULL)
{
go_deep_left->next = go_deep_right; go_deep_left = go_deep_left->right;
go_deep_right = go_deep_right->left;
}
} connect(root->right);
connect(root->left);
}
};
3月3日[Go_deep]Populating Next Right Pointers in Each Node的更多相关文章
- 【LeetCode】117. Populating Next Right Pointers in Each Node II 解题报告(Python)
[LeetCode]117. Populating Next Right Pointers in Each Node II 解题报告(Python) 标签: LeetCode 题目地址:https:/ ...
- Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II
题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...
- Leetcode 笔记 116 - Populating Next Right Pointers in Each Node
题目链接:Populating Next Right Pointers in Each Node | LeetCode OJ Given a binary tree struct TreeLinkNo ...
- [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
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 II
Populating Next Right Pointers in Each Node II Follow up for problem "Populating Next Right Poi ...
- 【leetcode】Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeLinkNode * ...
随机推荐
- Cucumber 入门一
(转自:http://www.cnblogs.com/jarodzz/archive/2012/07/02/2573014.html) 第一次看到Cucumber和BDD(Behavior Drive ...
- Android数据的四种存储方式之SQLite数据库
Test.java: /** * 本例解决的问题: * 核心问题:通过SQLiteOpenHelper类创建数据库对象 * 通过数据库对象对数据库的数据的操作 * 1.sql语句方式操作SQLite数 ...
- oc-03-OC访问OC源文件、C源文件中的函数
show.h #ifndef __OCDay01__Show__ #define __OCDay01__Show__ #include <stdio.h> extern void test ...
- ant脚本打jar包 自动获取时间以及项目svn版本号
1.关键代码,获取时间 <tstamp> <format property="touch.time" pattern="yyyy/MM/dd hh:mm ...
- 如何扩大VMware虚拟机的硬盘磁盘空间大小
首先,在虚拟机配置界面通过界面配置,直接扩大虚拟机硬盘大小: 而后,登陆虚拟机,在windows磁盘管理,更多操作中直接“重新扫描磁盘”,操作系统自动找到了多出来的磁盘空间: 最后,在老磁盘分区上通过 ...
- Branch and Bound:分支限界算法
http://blog.sciencenet.cn/blog-509534-728984.html 分支定界 (branch and bound) 算法是一种在问题的解空间树上搜索问题的解的方法.但与 ...
- Debian下MySQL配置
1 安装 $ apt-get install mysql-server $ apt-get install mysql-client 2 修改MySQL的口令 一般上一步会让你输入root密码,如果没 ...
- 自问自答-hadoop在安全模式下究竟干了什么见不得人的事
本来想自己从网上搜集整理的,但是发现吴超写的刚刚好,不多不少,所以直接转载(图片失效了,用自己的图片) http://www.superwu.cn/2013/08/23/548/ 在hadoop集群的 ...
- Code the Tree
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2292 Accepted: 878 Description A tree ...
- mysql颠覆实战笔记(七)--白话理解事务
今天我们学习web开发级mysql颠覆实战课程第9课没MYSQL事务(一):白话理解事务.前面有两节课第7讲:商品系统设计(四):商品属性设计之自定义属性,第8讲:商品系统设计(五):一维属性的商品价 ...