https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/

求二叉树的最大深度

深度优先搜索

/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int maxDepth(TreeNode *root) {
if(root == NULL)
return ; int ans = ;
int now_depth;
deep(root,ans,);
return ans;
} void deep(TreeNode *root, int &max_depth, int now_depth)
{
if(root->left == NULL && root->right == NULL)
max_depth = max_depth < now_depth ? now_depth : max_depth; now_depth++; if(root->left)
deep(root->left,max_depth,now_depth);
if(root->right)
deep(root->right,max_depth,now_depth);
}
};

LeetCode OJ-- Maximum Depth of Binary Tree的更多相关文章

  1. Leetcode | Minimum/Maximum Depth of Binary Tree

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

  2. leetcode 104 Maximum Depth of Binary Tree二叉树求深度

    Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...

  3. LeetCode 104. Maximum Depth of Binary Tree C++ 解题报告

    104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...

  4. [LeetCode] 104. Maximum Depth of Binary Tree 二叉树的最大深度

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  5. (二叉树 BFS DFS) leetcode 104. Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  6. [LeetCode 题解]: Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  7. LeetCode OJ Minimum Depth of Binary Tree 递归求解

        题目URL:https://leetcode.com/problems/minimum-depth-of-binary-tree/ 111. Minimum Depth of Binary T ...

  8. LeetCode 104. Maximum Depth of Binary Tree (二叉树的最大深度)

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  9. LeetCode 104. Maximum Depth of Binary Tree

    Problem: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along ...

  10. leetcode 104 Maximum Depth of Binary Tree ----- java

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

随机推荐

  1. django-simple-captcha 验证码干扰线随机点位

    CAPTCHA_NOISE_FUNCTIONS = ( 'captcha.helpers.noise_null',# 设置样式 'captcha.helpers.noise_arcs',# 设置干扰线 ...

  2. manjaro中文输入法已安装但切换不了解决方法

    情况如图所示,输入法安装了,但Ctrl+空格键或者鼠标选择切换都不行 解决方法: 打开家目录下面的.xprofile文件,如果没有这个文件就新建一个,加入下面内容 保存文件,退出. 重启电脑就可以了

  3. 策略模式—Java实现(转)

    1. 现实需求 客户有了新的需求,这时我们直接新增策略即可,改很少的代码.基本符合我们面向对象原则中的开闭原则(对扩展开放,对修改关系),实现了高内聚低耦合. 2. 策略模式定义 策略模式,又叫算法簇 ...

  4. Diycode开源项目 BaseApplication分析+LeakCanary第三方+CrashHandler自定义异常处理

    1.BaseApplication整个应用的开始 1.1.看一下代码 /* * Copyright 2017 GcsSloop * * Licensed under the Apache Licens ...

  5. sql中保留一位小数的百分比字符串拼接,替换函数,换行符使用

    select  num ,cast(round(convert(float,isnull((a.Sum_Num-d.Sum_Num),0))/convert(float,c.Sum_Store_Num ...

  6. as API一些容易忘记的属性和方法

    1.在flash动画里的一些动态文本会随着动画的执行,有抖动,解决问题的方法: tt为动画里的动态文本,tt.transform.matrix=null;

  7. 如何将int转换为datetime?

    $timestamp = 1210003200; $datetime = date('Y-m-d H:i:s', $timestamp); echo "该时间戳代表的时间:", $ ...

  8. jxl教程图文详解

    近来学习了下jxl的操作Excel报表功能,现有的API基本可以满足当前的需要,抽空做了一个学生成绩查询报表的例子. 先看效果图: 从图中可以看到这是一个交叉报表,横向到Q列,纵向有22行,全部是通过 ...

  9. leetcode 【 Set Matrix Zeroes 】python 实现

    题目: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. cl ...

  10. 虚拟机VMware安Mac OS时没有Apple mac选项

    相信大家很多人在虚拟机安装mac os时候发现在选择客户机操作系统时候,没有Apple mac os选项,这样就会导致无法进行下一步,下面我来给大家详细介绍怎么添加这一项. 1.首先安装unlocke ...