原题: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的更多相关文章

  1. 【LeetCode】117. Populating Next Right Pointers in Each Node II 解题报告(Python)

    [LeetCode]117. Populating Next Right Pointers in Each Node II 解题报告(Python) 标签: LeetCode 题目地址:https:/ ...

  2. 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 ...

  3. Leetcode 笔记 116 - Populating Next Right Pointers in Each Node

    题目链接:Populating Next Right Pointers in Each Node | LeetCode OJ Given a binary tree struct TreeLinkNo ...

  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 每个节点的右向指针

    Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...

  6. LEETCODE —— Populating Next Right Pointers in Each Node

    Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeLinkNode * ...

  7. LeetCode - Populating Next Right Pointers in Each Node II

    题目: Follow up for problem "Populating Next Right Pointers in Each Node". What if the given ...

  8. 【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 ...

  9. 【leetcode】Populating Next Right Pointers in Each Node

    Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeLinkNode * ...

随机推荐

  1. decide your linux OS is GUI or not

    Try:  ps -ef|grep X  The ps command will display information about a selection of the active process ...

  2. thinkphp模板中使用自定义函数

    注意:自定义函数要放在项目应用目录/common/common.php中. 这里是关键. 模板变量的函数调用格式:{$varname|function1|function2=arg1,arg2,### ...

  3. Blueprint编译过程

    Blueprint 编译概述 一.术语 Blueprint,像C++语言一下的,在游戏中使用前须要编译.当你在BP编辑器中,点击编译button时候.BP资源開始把属性和图例过程转换为一个类对象处理. ...

  4. 关于 " +new Date " 的个人见解

    今天晚上,在一个Javascript的Q群里,有人问下面这种代码是什么意思: var time = +new Date; 这段代码中,比较奇怪的是有一个加号,下面说说我个人的理解:这是对后面的对象做一 ...

  5. divide-conquer-combine(4.1 from the introduction to algorithm)

    this example is from chapter 4 in <the introduction to algorithm> the main idea is all showed ...

  6. BootStrap2学习日记1--网格系统

    在BoootStrap2的版本中采用的布局方式是12栏网格布局(把浏览器的Width分12栏,布局中使用每个元素所占格数的不同来达到各种布局),包括(固定)网格布局(Grid System)和流式网格 ...

  7. Cookie和Session(session过程和设置进程外session)

    cookie 和  session 的区别 cookie 是保存在客户端上的一种机制   而session 是保存在服务端的一种机制 cookie的理解: 打个简单的比方,一个人生病了去A医院看病,回 ...

  8. JavaWeb中的简单分页

    这次主要是讲解一下通过登录后对得到的数据进行分页,首先我们新建一个登录页面login.jsp,因为我们主要学习一下分页,所以登录验证的部分不再阐述,主要代码如下: <form action=&q ...

  9. CSS 实现行内和上下自适应的几种方法

    在写一个移动端网页,发现网页的头部搜索框两边各有固定宽度的按钮,搜索框可以根据宽度的变化来改变自己的宽度,达到填充的目的,也就是一种自适应吧,下面写写自己尝试的几种方法 一 利用css3 的width ...

  10. 泛型类型转为DataTable类型

    public static DataTable ConvertToDatatable<T>(IEnumerable<T> data) { PropertyDescriptorC ...