ICode9

精准搜索请尝试: 精确搜索
  • [Google] LeetCode 366 Find Leaves of Binary Tree2022-08-20 04:30:08

    Given the root of a binary tree, collect a tree's nodes as if you were doing this: Collect all the leaf nodes. Remove all the leaf nodes. Repeat until the tree is empty. Solution 每次需要删去叶子节点。 我们利用 \(dfs\):对于叶子节点的,我们将其深度返回 \(-1\).

  • [Google] LeetCode 2096 Step-By-Step Directions From a Binary Tree Node to Another2022-08-20 03:30:26

    You are given the root of a binary tree with n nodes. Each node is uniquely assigned a value from 1 to n. You are also given an integer startValue representing the value of the start node s, and a different integer destValue representing the value of the

  • 654. 最大二叉树2022-08-20 02:00:08

    654. 最大二叉树 给定一个不重复的整数数组 nums 。 最大二叉树 可以用下面的算法从 nums 递归地构建: 创建一个根节点,其值为 nums 中的最大值。 递归地在最大值 左边 的 子数组前缀上 构建左子树。 递归地在最大值 右边 的 子数组后缀上 构建右子树。 返回 nums

  • LeetCode/最大二叉树2022-08-20 01:31:22

    给定一个不重复的整数数组 nums 。 最大二叉树 可以用下面的算法从 nums 递归地构建: 创建一个根节点,其值为 nums 中的最大值 递归地在最大值 左边 的 子数组前缀上 构建左子树 递归地在最大值 右边 的 子数组后缀上 构建右子树 1. 暴力分治构造 暴力在于每次递归都要找一次最大

  • 【LeetCode】102.二叉树的层序遍历2022-08-19 23:34:14

    【LeetCode】102.二叉树的层序遍历 /* * 转载请说明出处与作者 * 作者:多巴胺dopamine */ 一 问题描述 1 题目 给你二叉树的根节点 root ,返回其节点值的 层序遍历 。 (即逐层地,从左到右访问所有节点)。 示例 1: 输入:root = [3,9,20,null,null,15,7] 输出:[[3],[9,20],[15,7]] 示

  • [Oracle] LeetCode 1740 Find Distance in a Binary Tree2022-08-19 03:30:08

    Given the root of a binary tree and two integers p and q, return the distance between the nodes of value p and value q in the tree. The distance between two nodes is the number of edges on the path from one to the other. Solution 求树上两个点之间的距离。很经

  • acwing2022秋招每日一题 1302. 层数最深叶子节点的和2022-08-17 21:04:34

    题目 给你一棵二叉树的根节点 root ,请你返回 层数最深的叶子节点的和 。 思路 根据层序遍历,访问所有节点。将每一层上的结点,进行统计,直到最后一层时,统计所有节点数。 解法 class Solution { public: int levelTravel(TreeNode *root, queue<TreeNode *> &q) {

  • 2022-8-16 剑指offer-二叉树2022-08-16 13:01:18

    剑指 Offer II 053. 二叉搜索树中的中序后继 难度中等57收藏分享切换为英文接收动态反馈 给定一棵二叉搜索树和其中的一个节点 p ,找到该节点在树中的中序后继。如果节点没有中序后继,请返回 null 。 节点 p 的后继是值比 p.val 大的节点中键值最小的节点,即按中序遍历

  • 根据数组构建二叉树2022-08-15 09:00:56

    // """ // 给定一个非空列表,一层一层的构建一个二叉树。 // 例如: // input=[5,7,9,2,4,6,3,1,8,10] // 我希望返回结果: // 5(0) // / \ // 7(1) 9(2) // / \ / \ // 2(3) 4(4) 6(5) 3(6) // / \ / // 1(7) 8

  • 力扣 101. 对称二叉树2022-08-15 01:00:46

    101. 对称二叉树 给你一个二叉树的根节点 root , 检查它是否轴对称。 示例 1: 输入:root = [1,2,2,3,4,4,3] 输出:true 示例 2: 输入:root = [1,2,2,null,3,null,3] 输出:false 提示: 树中节点数目在范围 [1, 1000] 内 -100 <= Node.val <= 100 题解 根据此题相同的树的基础,

  • 力扣 100.相同的数2022-08-15 00:01:33

    100. 相同的树 给你两棵二叉树的根节点 p 和 q ,编写一个函数来检验这两棵树是否相同。 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。   示例 1: 输入:p = [1,2,3], q = [1,2,3] 输出:true 示例 2: 输入:p = [1,2], q = [1,null,2] 输出:false 示例 3:

  • 递归回调的实现2022-08-14 01:32:25

    背景 异步树展开如果要实现展开回调比较困难,因为展开的过程是异步的。 前端:js引擎虽然是单线程执行,但是操作ui的线程是单独的,树的展开过程,就经历了js引擎线程+ui线程的过程,展开代码和展开回调的代码在不同时机执行的,本质上就是异步的。 展开回调的实现 展开回调的实现困难点在于判

  • 2022-8-13 剑指offer-二叉树递归2022-08-13 12:32:27

    剑指 Offer II 047. 二叉树剪枝 难度中等42收藏分享切换为英文接收动态反馈 给定一个二叉树 根节点 root ,树的每个节点的值要么是 0,要么是 1。请剪除该二叉树中所有节点的值为 0 的子树。 节点 node 的子树为 node 本身,以及所有 node 的后代。 1 /** 2 * De

  • 988. 从叶结点开始的最小字符串2022-08-12 22:02:35

      思路 难度中等87收藏分享切换为英文接收动态反馈 给定一颗根结点为 root 的二叉树,树中的每一个结点都有一个 [0, 25] 范围内的值,分别代表字母 'a' 到 'z'。 返回 按字典序最小 的字符串,该字符串从这棵树的一个叶结点开始,到根结点结束。 注:字符串中任何较短的前

  • 2022-8-12 剑指offer-队列2022-08-12 13:03:03

    剑指 Offer II 046. 二叉树的右侧视图 难度中等33收藏分享切换为英文接收动态反馈 给定一个二叉树的 根节点 root,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。 1 /** 2 * Definition for a binary tree node. 3 * public class TreeNode

  • 2022-8-11 剑指offer-队列2022-08-11 15:30:24

    剑指 Offer II 045. 二叉树最底层最左边的值 难度中等28收藏分享切换为英文接收动态反馈 给定一个二叉树的 根节点 root,请找出该二叉树的 最底层 最左边 节点的值。 假设二叉树中至少有一个节点。   1 /** 2 * Definition for a binary tree node. 3 * public cl

  • 力扣练习——59 从二叉搜索树到更大和树2022-08-07 18:01:56

    1.问题描述 给出二叉 搜索 树的根节点,该二叉树的节点值各不相同,修改二叉树,使每个节点 node 的新值等于原树中大于或等于 node.val 的所有节点的值之和。 提醒一下,二叉搜索树满足下列约束条件: 节点的左子树仅包含键 小于 节点键的节点。 节点的右子树仅包含键 大于 节点键的节点。

  • Element树形懒加载表格,数据刷新时刷新列表(触发懒加载)2022-08-07 09:00:08

    使用懒加载解决子节点增删后,不刷新新节点数据问题 <el-table :load="load" ref='myTable' data () { return { maps: new Map() } } methods: { load (row, treeNode, resolve) { // 存在map里 this.maps.set(row.id, {row, treeNode, resolve}) } // 当数据改变时需要重新执行懒

  • LeetCode 572 Subtree of Another Tree2022-08-04 04:31:06

    Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise. A subtree of a binary tree tree is a tree that consists of a node in tree and all of th

  • leetcode.98. 验证二叉搜索树2022-08-03 22:04:49

    给你一个二叉树的根节点 root ,判断其是否是一个有效的二叉搜索树。 有效 二叉搜索树定义如下: 节点的左子树只包含 小于 当前节点的数。节点的右子树只包含 大于 当前节点的数。所有左子树和右子树自身必须也是二叉搜索树。  示例 1:     输入:root = [2,1,3]输出:true示例 2:  

  • 【数据结构与算法】二叉树的遍历与构造2022-07-31 13:00:59

    根据先序和中序构建二叉树 测试样例: 先序:3,9,20,15,7 中序:9,3,15,20,7 结果:3,9,20,null,null,15,7 二叉树结构: public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } }

  • [LeetCode] 1161. Maximum Level Sum of a Binary Tree2022-07-31 06:31:07

    Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum of all the values of nodes at level x is maximal. Example 1: Input: root = [1,7,0,7,-8,null,null]

  • 剑指 Offer 68 - I. 二叉搜索树的最近公共祖先2022-07-30 19:02:00

    剑指 Offer 68 - I. 二叉搜索树的最近公共祖先 给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先。 百度百科中最近公共祖先的定义为:“对于有根树 T 的两个结点 p、q,最近公共祖先表示为一个结点 x,满足 x 是 p、q 的祖先且 x 的深度尽可能大(一个节点也可以是它自己的祖先

  • 二叉树的最大深度2022-07-29 19:03:35

    给定一个二叉树,找出其最大深度。 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。 说明: 叶子节点是指没有子节点的节点。 示例: 给定二叉树 [3,9,20,null,null,15,7], 3 / 9 20 / 15 7 返回它的最大深度 3 。 作者:力扣 (LeetCode) 链接:https://leetcode.cn/lee

  • LeetCode 108 Convert Sorted Array to Binary Search Tree DFS2022-07-29 06:31:26

    Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more tha

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

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

ICode9版权所有