首页 > TAG信息列表 > rightDepth

力扣 222. 完全二叉树的节点个数

最近开始刷力扣,将每日做题心得都会发布在这上面,以便日后查看。 起初看到这个题,忘记了完全二叉树的概念是什么,于是回顾一下。 这里参考了以下链接 满二叉树、完全二叉树、平衡二叉树、最优二叉树 时间复杂度:O(logn * logn) 空间复杂度:O(1) class Solution { public int coun

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

二叉树最大深度

二叉树最大深度 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数 struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; }; int maxDepth(struct TreeNode* root){ if(root == NULL) return 0; int

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

题目:     解答: 平衡二叉树要求左子树和右子树的高度相差为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