难度系数:easy

/**
* 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 minDepth(TreeNode* root) {
if(root==NULL)return 0;
if(root->left!=NULL&&root->right!=NULL)
return min(minDepth(root->left)+1,minDepth(root->right)+1);
else if(root->left==NULL&&root->right!=NULL) return minDepth(root->right)+1;
else if(root->right==NULL&&root->left!=NULL) return minDepth(root->left)+1;
else return 1;
}
};

7. Minimum Depth of Binary Tree-LeetCode的更多相关文章

  1. Minimum Depth of Binary Tree ——LeetCode

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

  2. Minimum Depth of Binary Tree [LeetCode]

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

  3. Minimum Depth of Binary Tree leetcode java

    题目: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the ...

  4. LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree

    LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...

  5. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  6. [LeetCode] 111. Minimum Depth of Binary Tree ☆(二叉树的最小深度)

    [Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 (最小有3种解法) 描述 解析 递归深度优先搜索 当求最大深度时,我们只要 ...

  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][JAVA] Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree

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

  9. 【LeetCode练习题】Minimum Depth of Binary Tree

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

  10. LeetCode My Solution: Minimum Depth of Binary Tree

    Minimum Depth of Binary Tree Total Accepted: 24760 Total Submissions: 83665My Submissions Given a bi ...

随机推荐

  1. 使用Keil下载Hex文件进STM32

    前言 初学STM32时,是通过串口1把Hex文件下载进STM32的,需要一个串口模块,而且还要设置BOOT0和BOOT1电平,然后通过FlyMcu软件进行下载,这也是一种不错的方法,这里我要介绍的是使 ...

  2. EasyX安装教程

    Easyx是什么 就是一款可以在Windows里让你的C++程序里显示图片等的工具. 注意:EasyX不支持Linux.MacOS.不过还有Qt等可以选择. 安装VC/VS Easyx只支持Visua ...

  3. Go语言核心36讲(Go语言进阶技术十二)--学习笔记

    18 | if语句.for语句和switch语句 现在,让我们暂时走下神坛,回归民间.我今天要讲的if语句.for语句和switch语句都属于 Go 语言的基本流程控制语句.它们的语法看起来很朴素,但 ...

  4. Java中Lambda表达式的进化之路

    Lambda表达式的进化之路 为什么要使用Lambda表达式 可以简洁代码,提高代码的可读性 可以避免匿名内部类定义过多导致逻辑紊乱 在原先实现接口抽象方法的时候,需要通过定义一个实现接口的外部类来实 ...

  5. WLAN-无线路由综合应用

    一.实验目的 掌握综合应用的配置 二.实验仪器设备及软件 实验仪器设备:路由器.三层交换机.3台二层交换机.AC.3台AP 软件:ensp   三.实验原理   四.实验内容与步骤 AC配置: [AC ...

  6. React 三大属性state,props,refs以及组件嵌套的应用

    React 三大属性state,props,refs以及组件嵌套的应用 该项目实现了一个简单的表单输入添加列表的内容 代码如下 <!DOCTYPE html> <html> & ...

  7. LeetCode刷题 字符串详解

    一.字符串常用的操作 1. string类 1.1 string的定义与初始化 1.1.1 string的定义 1.1.2 string的初始化 1.2 string的赋值与swap.大小操作.关系运 ...

  8. zookeeper问题在公司可以 回到家用家里网不行 目前还没有解决

    Opening socket connection to server 192.168.1.193/192.168.1.193:2181. Will not attempt to authentica ...

  9. Django 小实例S1 简易学生选课管理系统 5 实现注册功能

    Django 小实例S1 简易学生选课管理系统 第5节--实现注册功能 点击查看教程总目录 作者自我介绍:b站小UP主,时常直播编程+红警三,python1对1辅导老师. 本文涉及到的新的额外知识点: ...

  10. Highcharts › 自由绘图

    ... <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...