Re: [闲聊] 每日LeetCode

楼主: Rushia (みけねこ的鼻屎)   2023-07-10 20:05:42
https://leetcode.com/problems/minimum-depth-of-binary-tree/description/
111. Minimum Depth of Binary Tree
给你一个二元树,返回他的最小深度,最小深度为 root 节点到叶子节点的最小距离。
Example 1:
https://assets.leetcode.com/uploads/2020/10/12/ex_depth.jpg
Input: root = [3,9,20,null,null,15,7]
Output: 2
Example 2:
Input: root = [2,null,3,null,4,null,5,null,6]
Output: 5
思路:
1.用广度优先去traversal二元树,如果某个节点的左右两个子节点都为空,表示找到
最小深度。
Java Code:
作者: a9486l (a9486l)   2023-07-10 20:07:00
大师
作者: ririoshi (角落住民)   2023-07-10 20:10:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com