LeetCode基础--二叉树-求最小高度

来源:互联网 发布:python 字符串合并 编辑:程序博客网 时间:2024/06/05 06:11

题目描述:
求二叉树的最小高度.

实现:

public class Solution {    public int MinDepth(TreeNode root) {        if (root == null)         {            return 0;        }        int L = MinDepth(root.left);        int R = MinDepth(root.right);        return (L == 0 || R == 0) ? (L+R+1) : Math.Min(L,R) + 1;    }}
原创粉丝点击