首页 > TAG信息列表 > leftdepth

104. 二叉树的最大深度

class Solution { public int maxDepth(TreeNode root) { if (root == null){ return 0; } int leftDepth = maxDepth(root.left); int rightDepth = maxDepth(root.right); return Math.max(leftDepth, rightDe

[题解]剑指 Offer 55 - II. 平衡二叉树(C++)

题目 输入一棵二叉树的根节点,判断该树是不是平衡二叉树。如果某二叉树中任意节点的左右子树的深度相差不超过1,那么它就是一棵平衡二叉树。 示例 1: 给定二叉树 [3,9,20,null,null,15,7] 3 / \ 9 20 / \ 15 7 返回 true 。 示例 2: 给定二叉树 [1,2,2,3,3,n

【树】高度平衡二叉树的判定

题目:     解答: 平衡二叉树要求左子树和右子树的高度相差为1,且左右子树都是平衡二叉树,显然要计算二叉树的高度的函数。 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right;

[Leetcode] 104. Maximum Depth of Binary Tree

      1 int depth = 0; 2 int currentMaxDepth = 0; 3 public int maxDepth(TreeNode root) { 4 if(root == null){ 5 return 0; 6 } 7 8 int leftDepth = 1; 9 int rightDepth = 1;10 11