leetcode minimum-depth-of-binary-tree

来源:互联网 发布:js获取本地服务器地址 编辑:程序博客网 时间:2024/06/11 06:36

题目描述

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.

import java.util.*;public class Solution {    public int run(TreeNode root) {        if( root == null) return 0;        if( root != null && root.left == null && root.right == null) return 1;if( root.left == null ) return run( root.right)+1;        if( root.right == null ) return run( root.left)+1;        return Math.min(run(root.left),run(root.right))+1;    }}




0 0
原创粉丝点击