[Leetcode]Populating Next Right Pointers in Each Node
来源:互联网 发布:工业设计学什么软件 编辑:程序博客网 时间:2024/05/01 07:15
思路:逐层处理
/** * 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) { // Start typing your C/C++ solution below // DO NOT write int main() function while(root != NULL && root->left != NULL) { TreeLinkNode *cur = root; while(cur != NULL) { cur->left->next = cur->right; cur->right->next = cur->next != NULL ? cur->next->left : NULL; cur = cur->next; } root = root->left; } }};
- 【LeetCode】Populating Next Right Pointers in Each Node Populating Next Right Pointers in Each Node II
- leetcode Populating Next Right Pointers in Each Node &&Populating Next Right Pointers in Each Node||
- LeetCode Populating Next Right Pointers in Each Node & Populating Next Right Pointers in Each Node I
- 【Leetcode】Populating Next Right Pointers in Each Node in JAVA
- LeetCode Populating Next Right Pointers in Each Node
- LeetCode Populating Next Right Pointers in Each Node II
- [Leetcode] Populating Next Right Pointers in Each Node
- LeetCode: Populating Next Right Pointers in Each Node
- [Leetcode] Populating Next Right Pointers in Each Node II
- [LeetCode] Populating Next Right Pointers in Each Node
- [LeetCode] Populating Next Right Pointers in Each Node II
- 【leetcode】 Populating Next Right Pointers in Each Node
- leetcode 78: Populating Next Right Pointers in Each Node
- leetcode 79: Populating Next Right Pointers in Each Node II
- Leetcode: Populating Next Right Pointers in Each Node
- [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
- android图片的内存优化
- Oracle中表的非常全面的操作
- Android 锁屏和黑屏的广播消息
- linux之cp/scp命令+scp命令详解
- Andorid截屏代码
- [Leetcode]Populating Next Right Pointers in Each Node
- alwaysRetainTaskState=\"true\" 笔记
- 长连接与短连接 同步与异步(简介)
- 有关自定义View 中的画文本
- 最近遇到一个很蛋疼的问题 关于View的
- android:软件的安装和卸载源代码
- Android 下面三个按键添加声音
- 关于大小图片路径的问题; 在javabean 中加上getters
- 关于麻将发牌