ICode9

精准搜索请尝试: 精确搜索
  • JZ39 平衡二叉树2021-04-10 16:02:10

    平衡二叉树 题目:输入一棵二叉树,判断该二叉树是否是平衡二叉树。 在这里,我们只需要考虑其平衡性,不需要考虑其是不是排序二叉树 平衡二叉树(Balanced Binary Tree),具有以下性质:它是一棵空树或它的左右两个子树的高度差的绝对值不超过1,并且左右两个子树都是一棵平衡二叉树。   func

  • 菜鸡刷leetcode 剑指 Offer 55 - I. 二叉树的深度2021-04-01 22:04:35

    # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def maxDepth(self, root: TreeNode) -> int: if root == None:

  • 剑指 Offer 55 - I. 二叉树的深度(递归)2021-03-23 12:05:10

    public int maxDepth(TreeNode root) { if(root == null) return 0; return Math.max(maxDepth(root.left),maxDepth(root.right))+1; }

  • 检查“()”是否匹配并返回深度2021-03-11 19:33:15

    bool checkArr(char * arr, int len, int* max) { if (NULL == arr || len == 0 || max == NULL) { return false; } int maxdepth = 0, deep = 0; for (int i = 0; i < len; i++) { char tmp = arr[i]; if (tmp == 

  • PAT甲级题解 10212021-03-01 11:59:13

    先判断有几个连通块吗,因为已经满足边的个数等于顶点个数减1所以一定是一棵树,只要是1. 本来用的是优先队列,最后发现没过,其实是Error: K components 少了个s看题目一定要仔细 #include<bits/stdc++.h> using namespace std; const int MAXN = 10100; vector<int> G[MAXN]; int

  • 框架思维--104二叉树的最大深度2021-02-20 18:34:32

    [104. 二叉树的最大深度] 给定一个二叉树,找出其最大深度。 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。 说明: 叶子节点是指没有子节点的节点。 示例: 给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回它的最大深度 3 。 框架

  • 剑指 Offer 55 - I. 二叉树的深度2021-02-03 17:04:39

        思路:       统计层数,一开始想能不能dfs做,但怎么想感觉都不好做(脑袋里还是遍历的想法),然后自然就想到层序遍历,然后每次经过一层加一就行 class Solution { public int maxDepth(TreeNode root) { if(root==null) {return 0;} Queue<TreeNod

  • 二叉树的最大深度2021-02-02 22:01:25

    二叉树的最大深度 class Solution { public int maxDepth(TreeNode root) { if(root == null){ return 0; } int lh = maxDepth(root.left); int rh = maxDepth(root.right); return lh > rh ? lh + 1 : rh + 1;

  • 第40期:Keep Balance,平衡二叉树!2021-01-27 23:07:41

    我准备了 1000 本电子书和计算机各领域高清思维导图 100 张,关注后回复【资源】,即可获取!更可回复【内推】加入 BAT 内推群! 在之前的系列中,我们已经学习了二叉树最大深度以及DFS,如果不会可以先查看之前的文章。今天我们将对其进行应用,直接看题目。 01、题目分析 第110题:平衡二

  • 第35期:从 DFS 学习二叉树!(适合小白)2021-01-27 23:05:14

    我准备了 1000 本电子书和计算机各领域高清思维导图 100 张,关注后回复【资源】,即可获取!更可回复【内推】加入 BAT 内推群! 在计算机科学中,二叉树是每个结点最多有两个子树的树结构。通常子树被称作“左子树”(left subtree)和“右子树”(right subtree)。二叉树常被用于实现二叉查找

  • 剑指 Offer 55 - I. 二叉树的深度2021-01-21 10:59:02

    思路:递归,DFS或者BFS层次遍历 递归版本 class Solution { public int maxDepth(TreeNode root) { if (root == null) { return 0; } else { // 左子树高度 int leftHeight = maxDepth(root.left); // 右子

  • 递归的三部解题曲 关联leetcode 104. 二叉树最大深度练习2021-01-07 21:32:47

    递归关心的三点 1. 递归的终止条件 2. 一级递归需要做什么 3. 返回给上一级递归的返回值是什么 递归三部曲 1. 找到递归的终止条件:递归什么时候结束 2. 本级递归做什么:在这级递归中应当完成的任务 3. 找返回值:应该给上级递归返回什么信息 练手:leetcode 104.求二叉树的最大深度 lee

  • leetcode 104 二叉树的最大深度2021-01-01 17:58:36

    public int maxDepth(TreeNode root) { if (root == null) return 0; if (root.left == null && root.right == null){ return 1; } return Math.max(maxDepth(root.left)+1,maxDepth(root.right)+1); }

  • 剑指 Offer 55 - I. 二叉树的深度2020-12-17 12:34:06

    /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { public int maxDepth(TreeNode root) { if(root == nul

  • 0104. Maximum Depth of Binary Tree (E)2020-12-01 16:36:17

    Maximum Depth of Binary Tree (E) 题目 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Note: A leaf is a node with no children. Example: Given bin

  • 二叉树的深度2020-09-22 10:00:59

    输入一棵二叉树的根节点,求该树的深度。从根节点到叶节点依次经过的节点(含根、叶节点)形成树的一条路径,最长路径的长度为树的深度。 思考递归(例如对于关于树的相关操作):要从树叶到树根思考代码的运行过程! class TreeNode { int val; TreeNode left; TreeNode right;

  • 559. Maximum Depth of N-ary Tree2020-08-17 13:00:28

    Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Nary-Tree input serialization is represented in their level order traversal, each group of child

  • 104题-二叉树的最大深度2020-07-28 09:03:15

    1.1题目 给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。 说明: 叶子节点是指没有子节点的节点。 示例:给定二叉树 [3,9,20,null,null,15,7],返回它的最大深度 3 。 1.2解答 很显然是二叉树的遍历问题。遍历每个点然后返回当前点的深度,我

  • Leetcode打卡 二叉树的最大深度2020-05-25 23:04:46

    class Solution { public int maxDepth(TreeNode root) { if(root==null){ return 0; } else{ int leftTreeDepth=maxDepth(root.left); int rightTreeDepth=maxDepth(root.right); return

  • LeetCode 104. Maximum Depth of Binary Tree2020-03-06 14:42:20

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7],

  • LeetCode 104. Maximum Depth of Binary Tree(求树的高度)2020-02-29 21:03:29

    题意:求树的高度 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: int maxDepth(TreeN

  • 《剑指Offer(第二版)》面试题55 - II. 平衡二叉树2020-02-23 12:40:49

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

  • 树的最大深度2020-02-01 10:39:27

    题意 求解一棵二叉树的最大深度树这一类型的题目都可以考虑递归实现一颗树的深度就等于求解一棵树的左子和右子树的深度加1. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val =

  • [Leetcode] 104. Maximum Depth of Binary Tree2019-12-08 11:58:11

          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

  • 图解精选 TOP 面试题 002 | LeetCode 104. 二叉树的最大深度2019-12-01 10:51:38

    该系列题目取自 LeetCode 精选 TOP 面试题列表:https://leetcode-cn.com/problemset/top/ 题目描述 原题链接:https://leetcode-cn.com/problems/maximum-depth-of-binary-tree 给定一个二叉树,找出其最大深度。 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。 说明:

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有