Leetcode 117
if(root == NULL) return;
queue<TreeLinkNode *> que;
que.push(root);
while(!empty(que)){
int lens = que.size();
for(int i=;i < lens-;i++){
TreeLinkNode *temp = que.front();
que.pop();
temp->next = que.front();
if(temp->left) que.push(temp->left);
if(temp->right) que.push(temp->right);
}
TreeLinkNode *temp2 = que.front();
temp2->next = NULL;
que.pop();
if(temp2->left) que.push(temp2->left);
if(temp2->right) que.push(temp2->right);
}
_
Leetcode 117的更多相关文章
- Java for LeetCode 117 Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...
- [LeetCode] 117. Populating Next Right Pointers in Each Node II 每个节点的右向指针 II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...
- Java实现 LeetCode 117 填充每个节点的下一个右侧节点指针 II(二)
117. 填充每个节点的下一个右侧节点指针 II 给定一个二叉树 struct Node { int val; Node *left; Node *right; Node *next; } 填充它的每 ...
- [leetcode] 117. 填充同一层的兄弟节点 II
117. 填充同一层的兄弟节点 II 与116. 填充同一层的兄弟节点完全一样,二叉树的层次遍历..这是这次不是完美二叉树了 class Solution { public void connect( ...
- leetcode 117 Populating Next Right Pointers in Each Node II ----- java
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...
- Leetcode#117 Populating Next Right Pointers in Each Node II
原题地址 二叉树的层次遍历. 对于每一层,依次把各节点连起来即可. 代码: void connect(TreeLinkNode *root) { if (!root) return; queue< ...
- [leetcode]117. Populating Next Right Pointers in Each NodeII用next填充同层相邻节点
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...
- leetcode 117. 填充每个节点的下一个右侧节点指针 II(二叉树,DFS)
题目链接 https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node-ii/ 题目大意 给定一个二叉树 s ...
- leetcode & lintcode for bug-free
刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be it ...
随机推荐
- 《操作系统_FCFS和SJF》
先来先服务FCFS和短作业优先SJF进程调度 转自:https://blog.csdn.net/qq_34374664/article/details/73231072 一.概念介绍和案例解析 FCF ...
- Bytom交易说明(账户管理模式)
比原项目仓库: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom 该部分主 ...
- Redis,Memcache比较
简单比较: Redis不仅仅支持简单的k/v类型的数据,同时还提供list,set,hash等数据结构的存储.memcache只支持简单的K/V类型数据, 不过memcache可以缓存其他东西如图片, ...
- Ubuntu 14.04 安装sublime
参考 How do I install Sublime Text 2/3? Ubuntu 14.04 安装sublime 通过apt-get包管理器安装sublime. sublime2.0: sud ...
- 配置httpd支持https
1.首先为192.168.108.159创建私有CA #cd /etc/pki/CA # (umask 077;openssl genrsa -out private/cakey.pem 2048) ...
- Java基础 --Unix与Mac系统 文件路径分隔符(一)
斜杠‘/’与反斜杠‘\’在不同系统的使用 1)Window平台使用反斜杠'\'作为文件层级分隔符:Windows使用反斜杠作为DOS命令提示符的参数标志,随着发展DOS命令符逐渐被淘汰,大部分情况下斜 ...
- linux_nmon监控方法
一.介绍 Nmon 工具是 IBM 提供的免费的在AIX与各种Linux操作系统上广泛使用的监控与分析工具.该工具可将服务器的系统资源耗用情况收集起来并输出一个特定的文件,并可利用 excel 分析工 ...
- c# 通过反射输出成员变量以及成员变量的值
/*** @Author rexzhao* 工具类 仅限于* public variable*/using System.Collections;using System.Collections.Ge ...
- 【BZOJ】3572: [Hnoi2014]世界树
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3572 算是细节题了吧.. 构出虚树,考虑z正反DP两次求出虚树中每个点最近的议事处是哪一个 ...
- 【BZOJ】4542: [Hnoi2016]大数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4542 给定一个由数字构成的字符串${S_{1,2,3,...,n}}$,一个正素数$P$, ...