leetcode 日经贴,Cpp code -Populating Next Right Pointers in Each Node II
来源:互联网 发布:简单的java程序代码 编辑:程序博客网 时间:2024/05/22 02:03
Populating Next Right Pointers in Each Node II
/** * 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 update(TreeLinkNode *cur, TreeLinkNode *p) { p = p->next; while (p) { if (p->left) { cur->next = p->left; cur = cur->next; } if (p->right) { cur->next = p->right; cur = cur->next; } p = p->next; } cur->next = NULL; } void con(TreeLinkNode *r) { if (!r) return; TreeLinkNode *c = r->right? r->right:r->left; if (r->left && r->right) { r->left->next = r->right; } if (c && !c->next) { update(c, r); } con(r->left); con(r->right); } void connect(TreeLinkNode *root) { if (!root) return; root->next = NULL; con(root); }};
0 0
- leetcode 日经贴,Cpp code -Populating Next Right Pointers in Each Node II
- leetcode 日经贴,Cpp code -Populating Next Right Pointers in Each Node
- 【LeetCode】Populating Next Right Pointers in Each Node Populating Next Right Pointers in Each Node II
- CODE 16: Populating Next Right Pointers in Each Node II
- [leet code] Populating Next Right Pointers in Each Node II
- LeetCode Populating Next Right Pointers in Each Node II
- [Leetcode] Populating Next Right Pointers in Each Node II
- [LeetCode] Populating Next Right Pointers in Each Node II
- leetcode 79: Populating Next Right Pointers in Each Node II
- [Leetcode] Populating Next Right Pointers in Each Node ii
- leetcode Populating Next Right Pointers in Each Node II
- 【leetcode】Populating Next Right Pointers in Each Node II
- [Leetcode]Populating Next Right Pointers in Each Node II
- [leetcode] Populating Next Right Pointers in Each Node II
- LeetCode-Populating Next Right Pointers in Each Node II
- LeetCode - Populating Next Right Pointers in Each Node II
- [LeetCode]Populating Next Right Pointers in Each Node II
- leetcode Populating Next Right Pointers in Each Node II
- mini2440 --linux beaglebone black -- android
- 那个女孩
- POJ 2762 — Going from u to v or from v to u? 强连通+拓扑
- 每天一个学习一个新的php函数(2) fgetcsv()/fgets()
- 2015年05月02日 问题
- leetcode 日经贴,Cpp code -Populating Next Right Pointers in Each Node II
- DDS文件格式
- 第57题 Sum Root to Leaf Numbers
- IO学习笔记
- shader 入门 《顶点着色器 的输出 和 片段着色器的 输入》
- DDS支持的Mipmap Texture/Cubemap Texture/Volume Texture 纹理理解
- Choose the best route
- POJ 题目2449 Remmarguts' Date(K短路,A*+spfa)
- kbuild makefile