博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Minimum Depth of Binary Tree
阅读量:6936 次
发布时间:2019-06-27

本文共 630 字,大约阅读时间需要 2 分钟。

hot3.png

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.

/** * Definition for a binary tree node. * public class TreeNode { *     int val; *     TreeNode left; *     TreeNode right; *     TreeNode(int x) { val = x; } * } */class Solution {    public int minDepth(TreeNode root) {        return null == root ? 0 : (null != root.left && null != root.right) ? Math.min(minDepth(root.left), minDepth(root.right)) + 1 : Math.max(minDepth(root.left), minDepth(root.right)) + 1;    }}

 

转载于:https://my.oschina.net/gonglibin/blog/1624295

你可能感兴趣的文章
虚拟属性
查看>>
利用background-attachment做视差滚动效果
查看>>
许小年:宁可踏空,不可断粮<转>
查看>>
第三篇 第八章泡沫灭火系统(二)
查看>>
MYSQL explain 详解
查看>>
移动web-bootstrap
查看>>
洛谷1108 低价购买
查看>>
LeetCode Next Permutation
查看>>
[转载] 杜拉拉升职记——12 话不投机
查看>>
HTTP中的Session和Cookie浅析
查看>>
Java Note
查看>>
台北出差备忘
查看>>
Treap 实现名次树
查看>>
SSD 单发多框检测
查看>>
Layout 不可思议(二)—— 两侧定宽的三列布局
查看>>
Node.js学习笔记(八) --- Node.js的路由模块封装
查看>>
今天正式在博客园落家
查看>>
LeetCode 345. Reverse Vowels of a String
查看>>
Wireshark技巧-过滤规则和显示规则【转】
查看>>
Linux内核学习之中断 中断本质【转】
查看>>