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 ...
随机推荐
- 【前端开发工具】WijmoJS 2018 v3 正式发布,全面支持Angular7
WijmoJS(前端开发工具包)2018年度第三个大版本已经正式发布,本次更新除了全面支持Angular7之外,还允许用户使用Web Workers在前端更高效地导出PDF.智能的分组表头属性.全新的 ...
- 异步加载script,提高前端性能(defer和async属性的区别)
一.异步加载script的好处 为了加快首屏响应速度,前端会采用代码切割.按需加载等方式优化性能.异步加载script也是一种前端优化的手段. 就好比如果我的页面其中一个功能需要打开地图,但是地图的j ...
- Linux 服务器 安装 goflyway
github官方开发主页:https://github.com/coyove/goflyway goflyway的用途就不说了,你能搜到此文章就说明已经知道了. centos和Ubuntu均可使用,其 ...
- layout_gravity与gravity的区别,和padding margin的区别
https://blog.csdn.net/github_39688629/article/details/77790541
- 什么是可哈希的(hashable)
如果一个对象在自己的生命周期中有一哈希值(hash value)是不可改变的,那么它就是可哈希的(hashable)的,因为这些数据结构内置了哈希值,每个可哈希的对象都内置了__hash__方法,所以 ...
- Mysql一些常用语句
1.查询表创建的时间: SELECT CREATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERETABLE_NAME='TableName'
- 剖析Hadoop和Spark的Shuffle过程差异
一.前言 对于基于MapReduce编程范式的分布式计算来说,本质上而言,就是在计算数据的交.并.差.聚合.排序等过程.而分布式计算分而治之的思想,让每个节点只计算部分数据,也就是只处理一个分片,那么 ...
- leecode第四十六题(全排列)
class Solution { public: vector<vector<int>> permute(vector<int>& nums) { int ...
- (转)Qt中图片相对位置的引用
原文作者:locky1218 原文地址:https://blog.csdn.net/locky1218/article/details/9749703/ 一般使用相对位置的时候可能无法显示图片,可 ...
- Study之2 Glance相关操作-devstack
1,Glance的image是存储在backend中,backend配置在: /etc/glance/glance-api.conf.2, devstack默认:image 存放在控制节点本地目录 / ...