题目描述: ##求给定二叉树的最小深度。最小深度是指树的根结点到最近叶子结点的最短路径上结点的数量。
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shor
展开全文
题目描述求给定二叉树的最小深度。最小深度是指树的根结点到最近叶子结点的最短路径上结点的数量。Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest
展开全文
Leetcode刷题记录一求二叉树的最小深度(minimum-depth-of-binary-tree) 题目描述求给定二叉树的最小深度。最小深度是指树的根结点到最近叶子结点的最短路径上结点的数量。Given a binary tree, find its minimum depth.The min
展开全文
用一个全局变量min记录最小的节点深度即可。使用前序遍历,每次遍历前先把深度求出,如果某节点左右孩子为空则判断深度是否小于最小深度。如果小于最小深度则更新最小深度。
import java.util.*;
public class Solution {
Integer min = Integ
展开全文