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

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

Minimum Depth of Binary Tree

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.

Java代码:

/** * Definition for binary tree * public class TreeNode { *     int val; *     TreeNode left; *     TreeNode right; *     TreeNode(int x) { val = x; } * } */public class Solution {    public int minDepth(TreeNode root) {        if(null == root)				return 0;		if(null ==root.left && null == root.right)			return 1;		else if(null == root.left)			return minDepth(root.right)+1;		else if(null == root.right)			return minDepth(root.left)+1;		else			return minDepth(root.left)>minDepth(root.right)?minDepth(root.right)+1:minDepth(root.left)+1;    }}
 

转载地址:http://cnuni.baihongyu.com/

你可能感兴趣的文章
欧几里得空间
查看>>
今天写shader流光效果,shader代码少了个括号,unity shader compiler卡死且不提示原因...
查看>>
Unity shader saturate
查看>>
_LightColor0将会是主要的directional light的颜色。
查看>>
Unity的Shader如何控制投影颜色
查看>>
Unity3d 下websocket的使用
查看>>
unity与android交互总结
查看>>
android studio 开发android app 真机调试
查看>>
两分钟彻底让你明白Android Activity生命周期(图文)!
查看>>
这几天用高通VUFORIA的体会
查看>>
ARGB_8888
查看>>
HoloLens的显示分辨率有多少?
查看>>
ThreadPool(线程池) in .Net
查看>>
为什么3D模型的网格由很多三角形来组成
查看>>
U3D OnDrawGizmos
查看>>
Unity Remote 5 使用
查看>>
Unity中的Path对应各平台中的Path
查看>>
GameObject.Find 使用技巧
查看>>
Unity游戏语音(富文本消息)解决方案GVoice
查看>>
UGUI防止穿透和判断点击的是否是UI
查看>>