/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public int run(TreeNode root) {
if(root == null) return 0;
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;
}
}
leetCode 笔记 ————二叉树最小深度
最新推荐文章于 2024-02-19 22:06:43 发布