Minimum Depth of Binary Tree [LeetCode]
Given a binary tree, find its minimum depth.
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
Summary: BFS or DFS with recursion.
int minDepth(TreeNode *root) {
if(root == NULL)
return ;
if(root->left == NULL && root->right == NULL)
return ;
if(root->right == NULL)
return minDepth(root->left) + ;
if(root->left == NULL)
return minDepth(root->right) + ;
return min(minDepth(root->left), minDepth(root->right)) + ;
}
Minimum Depth of Binary Tree [LeetCode]的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- [LeetCode] 111. Minimum Depth of Binary Tree ☆(二叉树的最小深度)
[Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 (最小有3种解法) 描述 解析 递归深度优先搜索 当求最大深度时,我们只要 ...
- LeetCode OJ Minimum Depth of Binary Tree 递归求解
题目URL:https://leetcode.com/problems/minimum-depth-of-binary-tree/ 111. Minimum Depth of Binary T ...
- [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 ...
- 【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 ...
- LeetCode My Solution: Minimum Depth of Binary Tree
Minimum Depth of Binary Tree Total Accepted: 24760 Total Submissions: 83665My Submissions Given a bi ...
随机推荐
- wex5 实战 登陆帐号更换与用户id一致性
一 前言 关于用户登陆,注册,页面跳转,我讲了很多,都是页面框架级别的.有人问到这个问题,索性总结一下,今天是收尾最后一篇. 以往初学时的设计是: 1 注册 2 登陆 3 进入页面. 这种很简单,没有 ...
- libtool: line 990: g++: command not found的解决
yum -y install gcc+ gcc-c++
- android控件的对齐方式(转)
<?xml version="1.0" encoding="utf-8"?> <!-- android:layout_above 将该控件的底 ...
- Ajax开发中服务端Response的Content-Type
转自http://www.cnblogs.com/hyl8218/archive/2010/03/10/1681484.html ajax开发中在请求服务器端的响应时, 对于每一种返回类型 规范的做法 ...
- easyui DataGrid 工具类之 TableUtil class
import java.lang.reflect.InvocationTargetException;import java.util.ArrayList;import java.util.HashM ...
- 进军Linux
大二的时候学习Java,学完Java SE之后就放弃了这条道路,踏上了嵌入式之路.那时候约定好,选择了DSP,从C2000开始学起,基础仅仅是会C51,有C语言和Java的基础.这几年随着项目的需求变 ...
- angular源码阅读,依赖注入的原理:injector,provider,module之间的关系。
最开始使用angular的时候,总是觉得它的依赖注入方式非常神奇. 如果你跳槽的时候对新公司说,我曾经使用过angular,那他们肯定会问你angular的依赖注入原理是什么? 这篇博客其实是angu ...
- js 练习
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="req_form.aspx.cs ...
- 微信小程序-基础内容组件
icon 图标 示例: <view class="group"> <block wx:for="{{iconSize}}"> <i ...
- 合并excel中多个sheet
Sub 合并当前工作簿下的所有工作表() Application.ScreenUpdating = False For j = 1 To Sheets.Count If Sheets(j).Name ...