zoukankan      html  css  js  c++  java
  • leetcode--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.

    public class Solution {
        public int minDepth(TreeNode root) {
           int depth = 0;
    	   if(root != null){
    	        if(root.left == null)
    			    depth = 1 + minDepth(root.right);
    			else if(root.right == null)
    			    depth = 1 + minDepth(root.left);
    			else
    			    depth = 1 + Math.min(minDepth(root.left), minDepth(root.right));
    	   } 
    		return depth;
        }
    }
    

      

  • 相关阅读:
    Git的使用
    Flask(五)
    Flask(四)
    Flask(二)
    Flask(一)
    SDL 五子棋游戏
    c++单例模式
    ubuntu安装虚拟机
    git 命令
    汇编x86入门
  • 原文地址:https://www.cnblogs.com/averillzheng/p/3537467.html
Copyright © 2011-2022 走看看