LeetCode—***Populating Next Right Pointers in Each Node寻找树的层次上的右指针
来源:互联网 发布:牙齿填骨粉的利弊 知乎 编辑:程序博客网 时间:2024/06/11 01:39
Populating Next Right Pointers in Each Node
Total Accepted: 22481 Total Submissions: 63654My SubmissionsGiven a binary tree
struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL
.
Initially, all next pointers are set to NULL
.
Note:
- You may only use constant extra space.
- You may assume that it is a perfect binary tree (ie, all leaves are at the same level, and every parent has two children).
For example,
Given the following perfect binary tree,
1 / \ 2 3 / \ / \ 4 5 6 7
After calling your function, the tree should look like:
1 -> NULL / \ 2 -> 3 -> NULL / \ / \ 4->5->6->7 -> NULLAfter calling your function, the tree should look like:
这道题目非常有意思,就是根据二叉树寻找自己水平向右的节点,如果没有那么就为null。
下面是自己的解题思路,但是程序还有点问题
首先是将数进行层序遍历,存入一个vector当中,然后利用一个特点,每一层的最后一个索引为2的指数倍-1,利用这一点进行相应的判断
0 0
- LeetCode—***Populating Next Right Pointers in Each Node寻找树的层次上的右指针
- 【LeetCode-面试算法经典-Java实现】【116-Populating Next Right Pointers in Each Node(二叉树链接右指针)】
- Populating Next Right Pointers in Each Node 完美二叉树添加next指针 @LeetCode
- [Leetcode] Populating Next Right Pointers in Each Node 二叉树Next指针
- 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
- Leetcode——populating-next-right-pointers-in-each-node
- 【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
- Populating Next Right Pointers in Each Node II 寻找右节点(重重重)
- LeetCode OJ 之 Populating Next Right Pointers in Each Node (为每个结点填充右指针)
- LeetCode OJ 之 Populating Next Right Pointers in Each Node II(为每个结点填充右指针-二)
- leetCode 116.Populating Next Right Pointers in Each Node (为节点填充右指针) 解题思路和方法
- leetCode 117.Populating Next Right Pointers in Each Node II (为节点添加右指针) 解题思路和方法
- Google Android 官方培训课程中文版--分享链接
- 学习笔记1 -- libclurl
- http client遭遇Connection reset问题,以及解决方法
- 未来的方向
- java语言规范要求equals方法具有下面的特性
- LeetCode—***Populating Next Right Pointers in Each Node寻找树的层次上的右指针
- HDU 1269
- HashCode方法
- java中三种方式初始化数据域的方法
- java反射
- HDOJ 题目1556Color the ball(树状数组)
- 动态创建控件及以循环赋值之三
- 污损的等式
- LinkedHashMap讲解