题目

 1 class Solution {
2 public:
3 int minimum = INT_MIN;
4 vector<int>res;
5 int diameterOfBinaryTree(TreeNode* root) {
6 if(root == NULL) return 0;
7 if(root->left == NULL && root->right == NULL) return 0;
8 if(root->left == NULL) return height(root->right) ;
9 if(root->right == NULL) return height(root->left) ;
10 res.push_back(height(root->left) + height(root->right));
11 diameterOfBinaryTree(root->left);
12 diameterOfBinaryTree(root->right);
13 for(int i = 0;i < res.size();i++){
14 if(res[i] > minimum ) minimum = res[i];
15 }
16 return minimum;
17 //return height(root->left) + height(root->right) ;
18 }
19 int height(TreeNode* root){
20 if(root == NULL) return 0;
21 return max(height(root->left),height(root->right)) + 1;
22 }
23 };

LeetCode543.二叉树的直径的更多相关文章

  1. [Swift]LeetCode543. 二叉树的直径 | Diameter of Binary Tree

    Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...

  2. Leetcode543.Diameter of Binary Tree二叉树的直径

    给定一棵二叉树,你需要计算它的直径长度.一棵二叉树的直径长度是任意两个结点路径长度中的最大值.这条路径可能穿过根结点. 示例 : 给定二叉树 1 / \ 2    3 / \ 4  5 返回 3, 它 ...

  3. LeetCode 543. Diameter of Binary Tree (二叉树的直径)

    Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...

  4. [LeetCode] Diameter of Binary Tree 二叉树的直径

    Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...

  5. 14.Diameter of Binary Tree(二叉树的直径)

    Level:   Easy 题目描述: Given a binary tree, you need to compute the length of the diameter of the tree. ...

  6. Leetcode 543.二叉树的直径

    二叉树的直径 给定一棵二叉树,你需要计算它的直径长度.一棵二叉树的直径长度是任意两个结点路径长度中的最大值.这条路径可能穿过根结点. 示例 :给定二叉树 1 / \ 2 3 / \ 4 5 返回 3, ...

  7. 543 Diameter of Binary Tree 二叉树的直径

    给定一棵二叉树,你需要计算它的直径长度.一棵二叉树的直径长度是任意两个结点路径长度中的最大值.这条路径可能穿过根结点.示例 :给定二叉树          1         / \        2 ...

  8. [LeetCode] 543. 二叉树的直径 ☆(递归、数最大深度)

    描述 给定一棵二叉树,你需要计算它的直径长度.一棵二叉树的直径长度是任意两个结点路径长度中的最大值.这条路径可能穿过根结点. 示例 :给定二叉树 1 / \ 2 3 / \ 4 5 返回 3, 它的长 ...

  9. [LeetCode] 543. Diameter of Binary Tree 二叉树的直径

    Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...

随机推荐

  1. IDM(Internet Download Manager)—下载各类安装包(github代码、python包)、软件、视频、文档的神器,居家必备良药

    自从有了IDM (Internet Download Manager),不知迅雷.github加速器.镜像为何物.鸟枪换炮,过上了,"他娘的意大利炮"的幸福生活[CoderBaby ...

  2. jmeter跨线程使用token

    项目的接口测试,今早所有接口都不通了,查看原因是登录接口地址变了..... 原来的方式是每个线程中都写了登陆接口来获取token,但是因为登陆接口地址改变的原因,要改好多个登陆接口,所以就想把toke ...

  3. Springboot之登录模块探索(含Token,验证码,网络安全等知识)

    简介 登录模块很简单,前端发送账号密码的表单,后端接收验证后即可~ 淦!可是我想多了,于是有了以下几个问题(里面还包含网络安全问题): 1.登录时的验证码 2.自动登录的实现 3.怎么维护前后端登录状 ...

  4. JVM虚拟机(三):Java内存区域

    运行时数据区   Java虚拟机再执行Java程序过程中会把它所管理的内存划分为若干个不同分工的数据区域. 程序计数器   程序计数器时一块较小的内存空间,它可以看作是当前线程所执行的字节码的行号指示 ...

  5. 基于Python PIL实现简单图片格式转化器

    基于Python PIL实现简单图片格式转化器 目录 基于Python PIL实现简单图片格式转化器 1.简介 2.前期资料准备 2.1.1如何实现图片格式转换? 2.1.2如何保存需要大小的图片? ...

  6. Flink开发中的问题

    1. 流与批处理的区别 流处理系统 流处理系统,其节点间数据传输的标准模型是:当一条数据被处理完成后,序列化到缓存中,然后立刻通过网络传输到下一个节点,由下一个节点继续处理. 批处理系统 批处理系统, ...

  7. CVE-2019-2618任意文件上传漏洞复现

    CVE-2019-2618任意文件上传漏洞复现 漏洞介绍: 近期在内网扫描出不少CVE-2019-2618漏洞,需要复测,自己先搭个环境测试,复现下利用过程,该漏洞主要是利用了WebLogic组件中的 ...

  8. 最速下降法--MATLAB程序

    function x = fxsteep(f,e,a,b)x1 = a;x2 = b;Q = fxhesson(f,x1,x2);x0 = [x1,x2]';temp = [x0];fx1 = dif ...

  9. 安装篇五:安装MySQL(5.6.38版本)

    #1.MySQL安装 #1.准备环境 # No1:关闭:(iptables)selinux # No2:下载好安装包(这里使用 mysql-5.6.38.tar.gz 包安装) # No3:安装依赖包 ...

  10. Solon 1.2.12 发布,新的惊喜

    Solon 一个类似Springboot的微型开发框架.强调:克制 + 简洁 + 开放的原则.力求:更小.更快.更自由的体验. 所谓更小: 内核0.1m,最小Web开发单位0.2m(相比Springb ...