662. Maximum Width of Binary Tree
https://leetcode.com/problems/maximum-width-of-binary-tree/description/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int widthOfBinaryTree(TreeNode* root) {
int left = , right = , res = ;
queue<pair<int,TreeNode*>> q;
if (root != NULL) q.push({, root});
while (!q.empty()) {
int qsz = q.size();
for (int i = ; i < qsz; i++) {
int idx = q.front().first;
TreeNode* cur = q.front().second;
q.pop(); if (i == ) left = idx;
if (i == qsz - ) right = idx;
if (cur->left) q.push( { idx *, cur->left });
if (cur->right) q.push( { idx * + , cur->right });
}
res = max(res, right-left+);
}
return res;
}
};
662. Maximum Width of Binary Tree的更多相关文章
- 【LeetCode】662. Maximum Width of Binary Tree 解题报告(Python)
[LeetCode]662. Maximum Width of Binary Tree 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.co ...
- LC 662. Maximum Width of Binary Tree
Given a binary tree, write a function to get the maximum width of the given tree. The width of a tre ...
- [LeetCode] 662. Maximum Width of Binary Tree 二叉树的最大宽度
Given a binary tree, write a function to get the maximum width of the given tree. The width of a tre ...
- 662. Maximum Width of Binary Tree二叉树的最大宽度
[抄题]: Given a binary tree, write a function to get the maximum width of the given tree. The width of ...
- 【leetcode】662. Maximum Width of Binary Tree
题目如下: Given a binary tree, write a function to get the maximum width of the given tree. The width of ...
- [LeetCode]662. Maximum Width of Binary Tree判断树的宽度
public int widthOfBinaryTree(TreeNode root) { /* 层序遍历+记录完全二叉树的坐标,左孩子2*i,右孩子2*i+1 而且要有两个变量,一个记录本层节点数, ...
- [LeetCode] Maximum Width of Binary Tree 二叉树的最大宽度
Given a binary tree, write a function to get the maximum width of the given tree. The width of a tre ...
- [Swift]LeetCode662. 二叉树最大宽度 | Maximum Width of Binary Tree
Given a binary tree, write a function to get the maximum width of the given tree. The width of a tre ...
- 二叉树最大宽度 Maximum Width of Binary Tree
2018-07-27 15:55:13 问题描述: 问题求解: 题目中说明了最后的宽度计算其实是按照满二叉树来进行计算的,也就是说如果我们能够得到每层最左边的节点编号和最右边的节点编号,那么本题就可以 ...
随机推荐
- 从左到右的滑块-Au3
说明:使用selenium自动化登陆时会弹出滑块,做人机识别,使用Au3模拟鼠标移动轨迹--可验证通过 #include <MsgBoxConstants.au3> #include &l ...
- ASP.NET Core集成微信登录
工具: Visual Studio 2015 update 3 Asp.Net Core 1.0 1 准备工作 申请微信公众平台接口测试帐号,申请网址:(http://mp.weixin.qq.com ...
- easyui框架中关于dialog自带关闭事件的使用
easyui是一个开源的第三方控件库,虽然使用比较方便,但其中有些事件和样式会与其他的控件或者框架形成冲突. 今天谈一下easyui 中dialog这个控件(对话框) easyui dialog一般在 ...
- ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第十二天(非原创)
文章大纲 一.课程介绍二.Ngnix基础知识学习三.Ngnix在淘淘商城中使用四.参考资料下载五.参考文章 一.课程介绍 一共14天课程(1)第一天:电商行业的背景.淘淘商城的介绍.搭建项目工程.Sv ...
- 【Oracle】曾经的Oracle学习笔记(8-15)ER图,三大范式,数据库字典,视图,索引,序列
一.数据库建模 二.建表 三.数据库字典 四.DML语句 五.视图 六.索引 七.序列 八.DDL语句 Lesson 8 Overview of Data Modeling and Database ...
- windows安装ipython
一.安装python2.71.下载地址https://www.python.org/downloads/2.安装后修改本地变量-右击电脑-属性-高级系统设置-环境变量-用户变量-新建-变量名:path ...
- jsop解析获得htmldome
package com.open1111.jsoup; import org.apache.http.HttpEntity;import org.apache.http.client.methods. ...
- SAP云平台CloudFoundry中的用户自定义变量
CloudFoundry应用的manifest.xml里的env区域,允许用户自定义变量,如下图5个变量所示. 使用cf push部署到CloudFoundry之后,在SAP Cloud Platfo ...
- centos下的安装mysql,jdk
mysql: 如果你是用rpm安装, 检查一下RPM PACKAGE:rpm -qa | grep -i mysql如果mysql已经安装在本机,则会列出mysql安装过的文件 ,像mysql-ser ...
- 【洛谷4424】[HNOI/AHOI2018] 寻宝游戏(位运算思维题)
点此看题面 大致题意: 给你\(n\)个\(m\)位二进制数.每组询问给你一个\(m\)位二进制数,要求你从\(0\)开始,依次对于这\(n\)个数进行\(and\)或\(or\)操作,问有多少种方案 ...