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;
}
};

最新文章

  1. asp.net获取站点根目录下子目录的名称
  2. Flex弹性布局在移动设备上的应用
  3. D3 学习资源
  4. App上架审核指南翻译
  5. PD16 Generate Datebase For Sql2008R2时报脚本错误&ldquo;对象名sysproperties无效&rdquo;
  6. 如何创建一个有System用户权限的命令行
  7. 基于wax的lua IOS插件开发
  8. Android Launcher label和Main Activity保持不一致
  9. TIA Portal V12不能添加新的CPU
  10. Oracle的基本学习(三)&mdash;函数
  11. 【T-SQL进阶】02.理解SQL查询的底层原理
  12. python对象的基本操作代码
  13. 英语口语练习系列-C05-水电
  14. VC6中函数点go to definition报告the symbol XXX is undefined
  15. Django_简介
  16. MD5=======RBAC权限管理
  17. [CF1039E]Summer Oenothera Exhibition[根号分治+lct]
  18. IBatis.Net 视频教程 原创教程
  19. CentOS安装OpenResty(Nginx+Lua)开发环境
  20. 【BZOJ4543】Hotel加强版

热门文章

  1. Oracle权限管理
  2. java CountDownLatch 等待多线程完成
  3. ElasticSearch搜索demo
  4. linux下的tomcat开机自启动(亲测),更改静态ip
  5. java中的中文变量和方法
  6. hibernate课程 初探单表映射3-5 hibernate增删改查
  7. 谈谈我对MVC的View层实现的理解
  8. vue-cli之脚手架
  9. DBA的做法
  10. LeetCode Find Peak Element 找临时最大值