LeetCode 117. Populating Next Right Pointers in Each Node II
来源:互联网 发布:淘宝双十一满减规则 编辑:程序博客网 时间:2024/05/18 00:51
描述
把每层的节点连接起来,要求O(1)的空间
解决
不会,看了这个算法写的,利用一个辅助节点记录每一层的开始节点
/** * 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) return ; while (root) { TreeLinkNode temp(-1); TreeLinkNode *zz = &temp; while (root) { if (root -> left) { zz -> next = root -> left; zz = zz -> next; } if (root -> right) { zz -> next = root -> right; zz = zz -> next; } root = root -> next; } root = temp.next; } return ; }};
0 0
- LeetCode 117. Populating Next Right Pointers in Each Node II
- [LeetCode]117.Populating Next Right Pointers in Each Node II
- [Leetcode] 117. Populating Next Right Pointers in Each Node II
- [leetcode] 117.Populating Next Right Pointers in Each Node II
- [LeetCode]117. Populating Next Right Pointers in Each Node II
- Leetcode 117. Populating Next Right Pointers in Each Node II
- [leetcode]117. Populating Next Right Pointers in Each Node II
- LeetCode 117. Populating Next Right Pointers in Each Node II
- Leetcode 117. Populating Next Right Pointers in Each Node II
- [LeetCode] 117. Populating Next Right Pointers in Each Node II
- LeetCode 117. Populating Next Right Pointers in Each Node II
- leetcode-117. Populating Next Right Pointers in Each Node II
- Leetcode 117. Populating Next Right Pointers in Each Node II
- leetcode 117. Populating Next Right Pointers in Each Node II
- LeetCode 117. Populating Next Right Pointers in Each Node II
- leetcode 117. Populating Next Right Pointers in Each Node II
- [LeetCode] 117. Populating Next Right Pointers in Each Node II
- LeetCode#117. Populating Next Right Pointers in Each Node II
- 学习笔记之C++为什么将函数声明或者类的定义放在.h文件中,而将其实现放在原文件中
- sock5系列之centos6.5 搭建!(一)
- Camera Projection (相机投影)
- js从零开始第二天
- VS2013常用的一些快捷键
- LeetCode 117. Populating Next Right Pointers in Each Node II
- KDTree 【转】
- bzoj 1833 count 数字计数 数位dp
- static_cast、dynamic_cast、reinterpret_cast和const_cast之间的区别
- 第十二周 oj训练 宏定义将角度转换为弧度
- Android WebView 缓存处理
- Runtime
- mybatis中并发更新判断问题
- CSS设置行内元素和块级元素的水平居中、垂直居中