leetcode.com 2024-01-24
🟡1457.pseudo-palindromic-paths-in-a-binary-tree
🏷️ Tags
#bit_manipulation #tree #depth_first_search #breadth_first_search #binary_tree
🟡1457.pseudo-palindromic-paths-in-a-binary-tree
🏷️ Tags
#bit_manipulation #tree #depth_first_search #breadth_first_search #binary_tree
Telegraph
pseudo-palindromic-paths-in-a-binary-tree
Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be pseudo-palindromic if at least one permutation of the node values in the path is a palindrome. Return the number of pseudo-palindromic paths going from the…
leetcode.cn 2024-01-26
🔴2846.minimum-edge-weight-equilibrium-queries-in-a-tree
🏷️ Tags
#tree #graph #array #strongly_connected_component
🔴2846.minimum-edge-weight-equilibrium-queries-in-a-tree
🏷️ Tags
#tree #graph #array #strongly_connected_component
Telegraph
minimum-edge-weight-equilibrium-queries-in-a-tree
现有一棵由 n 个节点组成的无向树,节点按从 0 到 n - 1 编号。给你一个整数 n 和一个长度为 n - 1 的二维整数数组 edges ,其中 edges[i] = [ui, vi, wi] 表示树中存在一条位于节点 ui 和节点 vi 之间、权重为 wi 的边。 另给你一个长度为 m 的二维整数数组 queries ,其中 queries[i] = [ai, bi] 。对于每条查询,请你找出使从 ai 到 bi 路径上每条边的权重相等所需的 最小操作次数 。在一次操作中,你可以选择树上的任意一条边,并将其权重更改为任意值。…
leetcode.com 2025-02-21
🟡1261.find-elements-in-a-contaminated-binary-tree
🏷️ Tags
#tree #depth_first_search #breadth_first_search #design #hash_table #binary_tree
🟡1261.find-elements-in-a-contaminated-binary-tree
🏷️ Tags
#tree #depth_first_search #breadth_first_search #design #hash_table #binary_tree
Telegraph
find-elements-in-a-contaminated-binary-tree
Given a binary tree with the following rules:
leetcode.com 2025-02-22
🔴1028.recover-a-tree-from-preorder-traversal
🏷️ Tags
#tree #depth_first_search #string #binary_tree
🔴1028.recover-a-tree-from-preorder-traversal
🏷️ Tags
#tree #depth_first_search #string #binary_tree
Telegraph
recover-a-tree-from-preorder-traversal
We run a preorder depth-first search (DFS) on the root of a binary tree. At each node in this traversal, we output D dashes (where D is the depth of this node), then we output the value of this node. If the depth of a node is D, the depth of its immediate…
leetcode.com 2025-02-23
🟡889.construct-binary-tree-from-preorder-and-postorder-traversal
🏷️ Tags
#tree #array #hash_table #divide_and_conquer #binary_tree
🟡889.construct-binary-tree-from-preorder-and-postorder-traversal
🏷️ Tags
#tree #array #hash_table #divide_and_conquer #binary_tree
Telegraph
construct-binary-tree-from-preorder-and-postorder-traversal
Given two integer arrays, preorder and postorder where preorder is the preorder traversal of a binary tree of distinct values and postorder is the postorder traversal of the same tree, reconstruct and return the binary tree. If there exist multiple answers…
leetcode.com 2025-02-24
🟡2467.most-profitable-path-in-a-tree
🏷️ Tags
#tree #depth_first_search #breadth_first_search #graph #array
🟡2467.most-profitable-path-in-a-tree
🏷️ Tags
#tree #depth_first_search #breadth_first_search #graph #array
Telegraph
most-profitable-path-in-a-tree
There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. At every node i, there…
leetcode.cn 2025-04-04
🟡1123.lowest-common-ancestor-of-deepest-leaves
🏷️ Tags
#tree #depth_first_search #breadth_first_search #hash_table #binary_tree
🟡1123.lowest-common-ancestor-of-deepest-leaves
🏷️ Tags
#tree #depth_first_search #breadth_first_search #hash_table #binary_tree
Telegraph
lowest-common-ancestor-of-deepest-leaves
给你一个有根节点 root 的二叉树,返回它 最深的叶节点的最近公共祖先 。 回想一下:
leetcode.com 2025-04-04
🟡1123.lowest-common-ancestor-of-deepest-leaves
🏷️ Tags
#tree #depth_first_search #breadth_first_search #hash_table #binary_tree
🟡1123.lowest-common-ancestor-of-deepest-leaves
🏷️ Tags
#tree #depth_first_search #breadth_first_search #hash_table #binary_tree
Telegraph
lowest-common-ancestor-of-deepest-leaves
Given the root of a binary tree, return the lowest common ancestor of its deepest leaves. Recall that:
leetcode.cn 2025-05-23
🔴3068.find-the-maximum-sum-of-node-values
🏷️ Tags
#greedy #bit_manipulation #tree #array #dynamic_programming #sorting
🔴3068.find-the-maximum-sum-of-node-values
🏷️ Tags
#greedy #bit_manipulation #tree #array #dynamic_programming #sorting
Telegraph
find-the-maximum-sum-of-node-values
给你一棵 n 个节点的 无向 树,节点从 0 到 n - 1 编号。树以长度为 n - 1 下标从 0 开始的二维整数数组 edges 的形式给你,其中 edges[i] = [ui, vi] 表示树中节点 ui 和 vi 之间有一条边。同时给你一个 正 整数 k 和一个长度为 n 下标从 0 开始的 非负 整数数组 nums ,其中 nums[i] 表示节点 i 的 价值 。 Alice 想 最大化 树中所有节点价值之和。为了实现这一目标,Alice 可以执行以下操作 任意 次(包括 0 次):
leetcode.com 2025-05-23
🔴3068.find-the-maximum-sum-of-node-values
🏷️ Tags
#greedy #bit_manipulation #tree #array #dynamic_programming #sorting
🔴3068.find-the-maximum-sum-of-node-values
🏷️ Tags
#greedy #bit_manipulation #tree #array #dynamic_programming #sorting
Telegraph
find-the-maximum-sum-of-node-values
There exists an undirected tree with n nodes numbered 0 to n - 1. You are given a 0-indexed 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree. You are also given a positive…
leetcode.cn 2025-05-28
🟡3372.maximize-the-number-of-target-nodes-after-connecting-trees-i
🏷️ Tags
#tree #depth_first_search #breadth_first_search
🟡3372.maximize-the-number-of-target-nodes-after-connecting-trees-i
🏷️ Tags
#tree #depth_first_search #breadth_first_search
Telegraph
maximize-the-number-of-target-nodes-after-connecting-trees-i
有两棵 无向 树,分别有 n 和 m 个树节点。两棵树中的节点编号分别为[0, n - 1] 和 [0, m - 1] 中的整数。 给你两个二维整数 edges1 和 edges2 ,长度分别为 n - 1 和 m - 1 ,其中 edges1[i] = [ai, bi] 表示第一棵树中节点 ai 和 bi 之间有一条边,edges2[i] = [ui, vi] 表示第二棵树中节点 ui 和 vi 之间有一条边。同时给你一个整数 k 。 如果节点 u 和节点 v 之间路径的边数小于等于 k ,那么我们称节点…
leetcode.com 2025-05-28
🟡3372.maximize-the-number-of-target-nodes-after-connecting-trees-i
🏷️ Tags
#tree #depth_first_search #breadth_first_search
🟡3372.maximize-the-number-of-target-nodes-after-connecting-trees-i
🏷️ Tags
#tree #depth_first_search #breadth_first_search
Telegraph
maximize-the-number-of-target-nodes-after-connecting-trees-i
There exist two undirected trees with n and m nodes, with distinct labels in ranges [0, n - 1] and [0, m - 1], respectively. You are given two 2D integer arrays edges1 and edges2 of lengths n - 1 and m - 1, respectively, where edges1[i] = [ai, bi] indicates…
leetcode.cn 2025-05-29
🔴3373.maximize-the-number-of-target-nodes-after-connecting-trees-ii
🏷️ Tags
#tree #depth_first_search #breadth_first_search
🔴3373.maximize-the-number-of-target-nodes-after-connecting-trees-ii
🏷️ Tags
#tree #depth_first_search #breadth_first_search
Telegraph
maximize-the-number-of-target-nodes-after-connecting-trees-ii
有两棵 无向 树,分别有 n 和 m 个树节点。两棵树中的节点编号分别为[0, n - 1] 和 [0, m - 1] 中的整数。 给你两个二维整数 edges1 和 edges2 ,长度分别为 n - 1 和 m - 1 ,其中 edges1[i] = [ai, bi] 表示第一棵树中节点 ai 和 bi 之间有一条边,edges2[i] = [ui, vi] 表示第二棵树中节点 ui 和 vi 之间有一条边。 如果节点 u 和节点 v 之间路径的边数是偶数,那么我们称节点 u 是节点 v 的 目标节…
leetcode.com 2025-05-29
🔴3373.maximize-the-number-of-target-nodes-after-connecting-trees-ii
🏷️ Tags
#tree #depth_first_search #breadth_first_search
🔴3373.maximize-the-number-of-target-nodes-after-connecting-trees-ii
🏷️ Tags
#tree #depth_first_search #breadth_first_search
Telegraph
maximize-the-number-of-target-nodes-after-connecting-trees-ii
There exist two undirected trees with n and m nodes, labeled from [0, n - 1] and [0, m - 1], respectively. You are given two 2D integer arrays edges1 and edges2 of lengths n - 1 and m - 1, respectively, where edges1[i] = [ai, bi] indicates that there is an…
leetcode.cn 2025-07-24
🔴2322.minimum-score-after-removals-on-a-tree
🏷️ Tags
#bit_manipulation #tree #depth_first_search #array
🔴2322.minimum-score-after-removals-on-a-tree
🏷️ Tags
#bit_manipulation #tree #depth_first_search #array
Telegraph
minimum-score-after-removals-on-a-tree
存在一棵无向连通树,树中有编号从 0 到 n - 1 的 n 个节点, 以及 n - 1 条边。 给你一个下标从 0 开始的整数数组 nums ,长度为 n ,其中 nums[i] 表示第 i 个节点的值。另给你一个二维整数数组 edges ,长度为 n - 1 ,其中 edges[i] = [ai, bi] 表示树中存在一条位于节点 ai 和 bi 之间的边。 删除树中两条 不同 的边以形成三个连通组件。对于一种删除边方案,定义如下步骤以计算其分数:
leetcode.com 2025-07-24
🔴2322.minimum-score-after-removals-on-a-tree
🏷️ Tags
#bit_manipulation #tree #depth_first_search #array
🔴2322.minimum-score-after-removals-on-a-tree
🏷️ Tags
#bit_manipulation #tree #depth_first_search #array
Telegraph
minimum-score-after-removals-on-a-tree
There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the ith node. You are also given a 2D integer array edges of length…
leetcode.cn 2025-11-28
🔴2872.maximum-number-of-k-divisible-components
🏷️ Tags
#tree #depth_first_search
🔴2872.maximum-number-of-k-divisible-components
🏷️ Tags
#tree #depth_first_search
Telegraph
maximum-number-of-k-divisible-components
给你一棵 n 个节点的无向树,节点编号为 0 到 n - 1 。给你整数 n 和一个长度为 n - 1 的二维整数数组 edges ,其中 edges[i] = [ai, bi] 表示树中节点 ai 和 bi 有一条边。 同时给你一个下标从 0 开始长度为 n 的整数数组 values ,其中 values[i] 是第 i 个节点的 值 。再给你一个整数 k 。 你可以从树中删除一些边,也可以一条边也不删,得到若干连通块。一个 连通块的值 定义为连通块中所有节点值之和。如果所有连通块的值都可以被 k 整除,那么我们说这是一个…
leetcode.com 2025-11-28
🔴2872.maximum-number-of-k-divisible-components
🏷️ Tags
#tree #depth_first_search
🔴2872.maximum-number-of-k-divisible-components
🏷️ Tags
#tree #depth_first_search
Telegraph
maximum-number-of-k-divisible-components
There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given a…
leetcode.cn 2025-12-16
🔴3562.maximum-profit-from-trading-stocks-with-discounts
🏷️ Tags
#tree #depth_first_search #array #dynamic_programming
🔴3562.maximum-profit-from-trading-stocks-with-discounts
🏷️ Tags
#tree #depth_first_search #array #dynamic_programming
Telegraph
maximum-profit-from-trading-stocks-with-discounts
给你一个整数 n,表示公司中员工的数量。每位员工都分配了一个从 1 到 n 的唯一 ID ,其中员工 1 是 CEO。另给你两个下标从 1 开始的整数数组 present 和 future,两个数组的长度均为 n,具体定义如下:
leetcode.com 2025-12-16
🔴3562.maximum-profit-from-trading-stocks-with-discounts
🏷️ Tags
#tree #depth_first_search #array #dynamic_programming
🔴3562.maximum-profit-from-trading-stocks-with-discounts
🏷️ Tags
#tree #depth_first_search #array #dynamic_programming
Telegraph
maximum-profit-from-trading-stocks-with-discounts
You are given an integer n, representing the number of employees in a company. Each employee is assigned a unique ID from 1 to n, and employee 1 is the CEO. You are given two 1-based integer arrays, present and future, each of length n, where: