题库chevron_right分类chevron_right
account_tree

191 道题目
简单: 38中等: 105困难: 48

树 是技术面试里最常出现的能力维度之一。建议先掌握基础题型的边界处理,再逐步过渡到模式识别和复杂度 trade-off。

面试场景

高频考察问题建模、边界条件与口头表达的清晰度。

常见误区

只背模板不解释为什么,容易在追问里失分。

练习策略

每轮练 3-5 题,固定复盘复杂度和可替代解法。

推荐练习顺序

#题目难度
94

二叉树的中序遍历

Binary Tree Inorder Traversal asks you to visit left subtree, node, then right subtree without losing position while mov…

简单
95

不同的二叉搜索树 II

Generate all structurally unique BSTs with values 1 to n using backtracking and recursive tree construction techniques.

中等
96

不同的二叉搜索树

Given n nodes, calculate the number of unique binary search trees (BSTs) that can be formed with values from 1 to n.

中等
98

验证二叉搜索树

Validate Binary Search Tree problem checks if a binary tree satisfies BST properties using tree traversal and state trac…

中等
99

恢复二叉搜索树

Recover a BST where two nodes are swapped by mistake using in-order traversal and careful state tracking to restore corr…

中等
100

相同的树

Check whether two binary trees are identical by comparing structure and node values using DFS or BFS traversal strategie…

简单
101

对称二叉树

Determine if a binary tree is symmetric by comparing left and right subtrees using DFS or BFS traversal techniques effic…

简单
102

二叉树的层序遍历

Perform a level order traversal on a binary tree using BFS to return node values level by level.

中等
103

二叉树的锯齿形层序遍历

Traverse a binary tree in zigzag level order, alternating directions at each depth using BFS and state tracking techniqu…

中等
104

二叉树的最大深度

Find the maximum depth of a binary tree using traversal techniques to track the longest path from root to leaf.

简单
105

从前序与中序遍历序列构造二叉树

Construct a binary tree using preorder and inorder traversal arrays, leveraging array scanning and hash table lookups.

中等
106

从中序与后序遍历序列构造二叉树

Reconstruct a binary tree from given inorder and postorder arrays using array scanning and hash lookup to optimize recur…

中等
107

二叉树的层序遍历 II

Return a bottom-up level order traversal of a binary tree, processing nodes left to right while tracking each level accu…

中等
108

将有序数组转换为二叉搜索树

Pick the middle element as root at each step so the sorted array becomes a height-balanced BST with valid ordering.

简单
109

有序链表转换二叉搜索树

Convert a sorted singly linked list into a height-balanced BST using pointer manipulation and divide-and-conquer recursi…

中等
110

平衡二叉树

Determine if a binary tree is height-balanced using tree traversal and state tracking techniques.

简单
111

二叉树的最小深度

Find the minimum depth of a binary tree, which is the shortest path from the root node to the nearest leaf node.

简单
112

路径总和

Determine if a binary tree has a root-to-leaf path where the sum of node values equals a given target sum, using DFS or …

简单
113

路径总和 II

Find all root-to-leaf paths in a binary tree where the sum of node values equals a given target using DFS backtracking.

中等
114

二叉树展开为链表

Flatten a binary tree into a right-skewed linked list by manipulating pointers following a pre-order traversal, handling…

中等
116

填充每个节点的下一个右侧节点指针

Connect each node across every level by reusing established next links to traverse a perfect binary tree without extra q…

中等
117

填充每个节点的下一个右侧节点指针 II

Populate each next pointer in a binary tree to its immediate right node, handling nulls and uneven levels efficiently us…

中等
124

二叉树中的最大路径和

Calculate the maximum sum of any path in a binary tree by exploring all node sequences using DFS and dynamic programming…

困难
129

求根节点到叶节点数字之和

Calculate the sum of all root-to-leaf numbers in a binary tree where each path represents a number.

中等
144

二叉树的前序遍历

Perform a binary tree preorder traversal by visiting root nodes first, then left and right subtrees, tracking state iter…

简单
145

二叉树的后序遍历

Solve Binary Tree Postorder Traversal using state tracking and binary-tree traversal techniques, focusing on Stack, Tree…

简单
173

二叉搜索树迭代器

Implement an iterator for in-order traversal of a binary search tree (BST), maintaining traversal state with stack-based…

中等
199

二叉树的右视图

The Binary Tree Right Side View problem asks you to return the visible nodes from the right side of a binary tree, trave…

中等
222

完全二叉树的节点个数

Count Complete Tree Nodes efficiently by leveraging binary-tree traversal, exploiting completeness, and applying bit man…

简单
226

翻转二叉树

Invert Binary Tree swaps every node's left and right children using tree traversal, with recursive DFS or iterative BFS …

简单
230

二叉搜索树中第 K 小的元素

Find the kth smallest element in a BST by leveraging in-order traversal to efficiently track node order and count.

中等
235

二叉搜索树的最近公共祖先

Find the lowest common ancestor (LCA) of two nodes in a binary search tree, using binary-tree traversal and state tracki…

中等
236

二叉树的最近公共祖先

Identify the lowest common ancestor of two nodes in a binary tree using traversal and state tracking techniques efficien…

中等
257

二叉树的所有路径

Find all root-to-leaf paths in a binary tree using DFS and backtracking, constructing strings for each complete path eff…

简单
297

二叉树的序列化与反序列化

This problem asks to serialize and deserialize a binary tree, requiring an efficient approach to handle traversal and st…

困难
331

验证二叉树的前序序列化

Determine if a given string correctly represents a binary tree preorder traversal using state tracking and slot counting…

中等
337

打家劫舍 III

Maximize the loot by robbing non-adjacent houses in a binary tree structure using dynamic programming and DFS.

中等
341

扁平化嵌套列表迭代器

Implement an iterator to flatten a nested list of integers, accounting for potential nesting levels.

中等
404

左叶子之和

Compute the total of all left leaves in a binary tree using precise traversal and state tracking techniques for correctn…

简单
427

建立四叉树

Construct a Quad-Tree from a binary matrix by recursively subdividing regions and tracking uniform states efficiently.

中等
429

N 叉树的层序遍历

Perform a level order traversal on an n-ary tree, capturing nodes by depth using breadth-first search with careful state…

中等
437

路径总和 III

Path Sum III challenges you to count paths in a binary tree that sum to a given target value with downward traversal.

中等
449

序列化和反序列化二叉搜索树

Design an algorithm to serialize and deserialize a binary search tree with efficient traversal and state tracking.

中等
450

删除二叉搜索树中的节点

Delete Node in a BST hinges on removing one target while preserving in-order ordering through carefully chosen subtree r…

中等
501

二叉搜索树中的众数

Find Mode in Binary Search Tree asks to identify the most frequent element(s) in a BST using binary-tree traversal.

简单
508

出现次数最多的子树元素和

Identify the most frequent subtree sum in a binary tree using DFS and hash table tracking for efficient state management…

中等
513

找树左下角的值

Find the leftmost value in the last row of a binary tree using efficient traversal strategies.

中等
515

在每个树行中找最大值

Find the largest value in each row of a binary tree using depth-first or breadth-first search techniques.

中等
530

二叉搜索树的最小绝对差

Find the minimum absolute difference between values of any two nodes in a BST using tree traversal and careful state tra…

简单
538

把二叉搜索树转换为累加树

Convert a BST into a Greater Tree by updating each node’s value with the sum of all greater values in the tree.

中等
543

二叉树的直径

The Diameter of Binary Tree problem involves finding the longest path between any two nodes using tree traversal techniq…

简单
558

四叉树交集

Compute the logical OR of two binary matrices represented as Quad-Trees using recursive tree traversal and state propaga…

中等
559

N 叉树的最大深度

Find the maximum depth of an N-ary tree, leveraging tree traversal techniques and state tracking.

简单
563

二叉树的坡度

Calculate the sum of the binary tree's node tilts using tree traversal and state tracking.

简单
572

另一棵树的子树

Determine if one binary tree is an exact subtree of another by comparing structure and node values recursively.

简单
589

N 叉树的前序遍历

Solve the N-ary Tree Preorder Traversal problem using depth-first search and stack-based traversal methods.

简单
590

N 叉树的后序遍历

Postorder traversal of an N-ary tree can be efficiently solved using DFS and stack-based methods, tracking state across …

简单
606

根据二叉树创建字符串

Given a binary tree, construct a string representation based on preorder traversal while adhering to specific formatting…

中等
617

合并二叉树

Merge Two Binary Trees requires combining nodes by summing overlapping values while preserving non-null nodes from eithe…

简单
623

在二叉树中增加一行

The problem requires adding a row of nodes to a binary tree at a specified depth.

中等
637

二叉树的层平均值

Calculate the average value of nodes on each level of a binary tree using traversal and state tracking.

简单
652

寻找重复的子树

Identify all duplicate subtrees in a binary tree by efficiently tracking structure and values with depth-first traversal…

中等
653

两数之和 IV - 输入二叉搜索树

Determine if a binary search tree contains two nodes whose values sum to a target using efficient traversal and state tr…

简单
654

最大二叉树

Construct a maximum binary tree by recursively selecting the largest element and dividing the array into left and right …

中等
655

输出二叉树

Print Binary Tree requires arranging a binary tree into a visually structured matrix using precise traversal and positio…

中等
662

二叉树最大宽度

Determine the maximum width of a binary tree by calculating the width of each level and considering the positions of the…

中等
669

修剪二叉搜索树

Trim a Binary Search Tree by maintaining its structure while removing nodes outside a given range.

中等
671

二叉树中第二小的节点

Find the second minimum node in a binary tree by traversing the tree and tracking state.

简单
687

最长同值路径

Find the longest path in a binary tree where all nodes share the same value using depth-first search efficiently.

中等
690

员工的重要性

Calculate an employee's total importance including all direct and indirect subordinates using array scanning and hash lo…

中等
700

二叉搜索树中的搜索

Locate a target value in a binary search tree and return the subtree rooted at that node using efficient tree traversal …

简单
701

二叉搜索树中的插入操作

Insert a value into a Binary Search Tree while maintaining the BST properties, focusing on tree traversal and state trac…

中等
703

数据流中的第 K 大元素

Find the kth largest element in a dynamic stream using binary-tree traversal and efficient state tracking with a min-hea…

简单
783

二叉搜索树节点最小距离

Find the minimum difference between values of two different nodes in a Binary Search Tree using tree traversal and state…

简单
814

二叉树剪枝

Binary Tree Pruning removes subtrees not containing a 1, applying binary-tree traversal with state tracking.

中等
834

树中距离之和

The problem asks to compute the sum of distances between each node and all others in a tree structure using depth-first …

困难
863

二叉树中所有距离为 K 的结点

Find all nodes at distance K from a target node in a binary tree using various tree traversal techniques.

中等
865

具有所有最深节点的最小子树

Find the smallest subtree that contains all the deepest nodes in a binary tree.

中等
872

叶子相似的树

Determine if two binary trees have identical leaf sequences using efficient traversal and state tracking techniques.

简单
889

根据前序和后序遍历构造二叉树

Reconstruct a binary tree from preorder and postorder traversals using array scanning and hash lookup.

中等
894

所有可能的真二叉树

Generate all possible full binary trees with n nodes, focusing on dynamic programming and binary tree traversal.

中等
897

递增顺序搜索树

Rearrange a binary search tree so all nodes follow increasing order with only right children using in-order traversal.

简单
919

完全二叉树插入器

Implement a data structure to insert nodes into a complete binary tree while preserving its completeness efficiently.

中等
938

二叉搜索树的范围和

Given a BST and a range, calculate the sum of all node values within that range.

简单
951

翻转等价二叉树

Determine if two binary trees are flip equivalent by recursively swapping subtrees.

中等
958

二叉树的完全性检验

Determine if a binary tree is complete by verifying its node structure and leftmost placement in the last level.

中等
965

单值二叉树

Determine if a binary tree is uni-valued using traversal and state tracking techniques.

简单
968

监控二叉树

Determine the minimum number of cameras required to monitor every node in a binary tree using efficient DFS and state tr…

困难
971

翻转二叉树以匹配先序遍历

Determine the minimum set of nodes to flip in a binary tree so its pre-order traversal matches a given voyage sequence.

中等
979

在二叉树中分配硬币

Minimize the number of moves needed to distribute coins in a binary tree so that each node has exactly one coin.

中等
987

二叉树的垂序遍历

Perform a vertical order traversal of a binary tree, sorting nodes by their values within columns.

困难
988

从叶结点开始的最小字符串

Determine the lexicographically smallest string from a leaf to root using binary-tree traversal and careful state tracki…

中等
993

二叉树的堂兄弟节点

Determine if two nodes in a binary tree are cousins by leveraging binary-tree traversal and state tracking.

简单
998

最大二叉树 II

The Maximum Binary Tree II problem requires building a binary tree by inserting a value into a maximum binary tree while…

中等
1008

前序遍历构造二叉搜索树

Construct a binary search tree directly from a preorder traversal array using stack-based state tracking efficiently.

中等
1022

从根到叶的二进制数之和

Calculate the sum of binary numbers from root to leaf paths in a binary tree.

简单
1026

节点与其祖先之间的最大差值

Find the maximum absolute difference between a node and its ancestor in a binary tree.

中等
1028

从先序遍历还原二叉树

Recover a binary tree from its preorder traversal string by tracking node depth and reconstructing child relationships e…

困难
1038

从二叉搜索树到更大和树

Convert a Binary Search Tree to a Greater Sum Tree by accumulating all larger node values using reverse in-order travers…

中等
1080

根到叶路径上的不足节点

Remove nodes in a binary tree whose all root-to-leaf paths sum to less than a given limit using DFS traversal and state …

中等
1104

二叉树寻路

The problem involves finding the path from the root to a node in a zigzag-labelled binary tree.

中等
1110

删点成林

Delete nodes from a binary tree using array scanning and hash lookup to return the remaining forest efficiently.

中等
1123

最深叶节点的最近公共祖先

Find the lowest common ancestor of the deepest leaves in a binary tree using efficient traversal and state tracking tech…

中等
1145

二叉树着色游戏

A two-player game where players color nodes in a binary tree, aiming to outmaneuver each other by choosing adjacent node…

中等
1161

最大层内元素和

Find the level of a binary tree where the sum of its nodes is maximal, with an emphasis on binary-tree traversal.

中等
1261

在受污染的二叉树中查找元素

Recover values in a contaminated binary tree and efficiently check for existence using traversal and state tracking tech…

中等
1302

层数最深叶子节点的和

Find the sum of the deepest leaves in a binary tree by using tree traversal and state tracking techniques.

中等
1305

两棵二叉搜索树中的所有元素

Merge elements from two binary search trees and return them sorted in ascending order.

中等
1315

祖父节点值为偶数的节点和

This problem involves calculating the sum of nodes with an even-valued grandparent in a binary tree.

中等
1325

删除给定值的叶子节点

In this problem, you need to delete all leaf nodes in a binary tree with a given target value, performing continuous del…

中等
1339

分裂二叉树的最大乘积

Maximize the product of sums of two subtrees formed by splitting a binary tree.

中等
1361

验证二叉树

Validate Binary Tree Nodes problem requires checking if a set of nodes forms a valid binary tree using graph traversal.

中等
1367

二叉树中的链表

Determine if a linked list is represented as a downward path in a binary tree using pointer traversal and recursive chec…

中等
1372

二叉树中的最长交错路径

Find the longest ZigZag path in a binary tree using depth-first search and dynamic programming for precise node state tr…

中等
1373

二叉搜索子树的最大键值和

Find the maximum sum of values from any Binary Search Tree (BST) subtree in a binary tree.

困难
1376

通知所有员工所需的时间

Calculate the time needed for the head of a company to inform all employees using tree traversal techniques.

中等
1377

T 秒后青蛙的位置

The problem asks for the probability that a frog reaches a target vertex after t seconds in a tree graph.

困难
1379

找出克隆二叉树中的相同节点

Find the corresponding node in a cloned binary tree using binary-tree traversal and state tracking.

简单
1382

将二叉搜索树变平衡

This problem requires balancing a binary search tree using in-order traversal and state tracking techniques.

中等
1443

收集树上所有苹果的最少时间

Minimize the time spent to collect all apples in a tree, considering traversal and state tracking with binary tree techn…

中等
1448

统计二叉树中好节点的数目

Count Good Nodes in Binary Tree identifies nodes exceeding all previous values along their path using DFS traversal tech…

中等
1457

二叉树中的伪回文路径

Count all root-to-leaf paths in a binary tree that can be rearranged to form a palindrome using bitwise state tracking.

中等
1483

树节点的第 K 个祖先

Find the kth ancestor of any node in a tree using efficient binary-tree traversal and dynamic state tracking methods.

困难
1519

子树中标签相同的节点数

Compute the number of nodes in each subtree sharing the same label using DFS with hash table aggregation efficiently.

中等
1530

好叶子节点对的数量

Find the number of good leaf node pairs in a binary tree where the shortest path between them is less than or equal to a…

中等
1569

将子数组重新排序得到同一个二叉搜索树的方案数

Determine the number of ways to reorder an array to get the same binary search tree (BST) from its insertion order.

困难
1600

王位继承顺序

Throne Inheritance requires modeling a dynamic family tree with births and deaths to determine the kingdom's inheritance…

中等
1609

奇偶树

Determine if a binary tree meets Even-Odd rules by checking value parity and strict ordering at each level efficiently.

中等
1617

统计子树中城市之间最大距离

This problem asks you to count subtrees in a tree structure where the maximum distance between any two cities matches sp…

困难
1719

重构一棵树的方案数

Determine how many distinct rooted trees can be reconstructed from given node pairs using careful traversal and state tr…

困难
1766

互质树

Determine the closest coprime ancestor for each node in a tree using efficient traversal and state tracking of node valu…

困难
1916

统计为蚁群构筑房间的不同顺序

Solve the problem of counting distinct ways to build rooms in an ant colony using dynamic programming and topological or…

困难
1932

合并多棵二叉搜索树

This problem asks you to merge multiple BSTs into a single valid BST by performing a series of operations.

困难
1993

树上的操作

Design a tree data structure that allows locking, unlocking, and upgrading nodes with user-specific actions.

中等
2003

每棵子树内缺失的最小基因值

Determine the smallest missing genetic value in each subtree using binary-tree traversal and precise state tracking effi…

困难
2049

统计最高分的节点数目

Find the number of nodes with the highest score in a binary tree, based on subtree sizes and node removal.

中等
2096

从二叉树一个节点到另一个节点每一步的方向

Find the shortest path between two nodes in a binary tree and output the directions as a string of 'L', 'R', and 'U'.

中等
2196

根据描述创建二叉树

Build a binary tree from descriptions of parent-child relationships using array scanning and hash lookup.

中等
2236

判断根结点是否等于子结点之和

Check if a binary tree root value equals the sum of its immediate left and right child nodes efficiently.

简单
2246

相邻字符不同的最长路径

Find the longest path in a tree where adjacent nodes have different characters using graph DFS and topological reasoning…

困难
2265

统计值等于子树平均值的节点数

Given a binary tree, count nodes where the value equals the average of values in its subtree.

中等
2322

从树中删除边的最小分数

Compute the minimum score after removing two edges in a tree using DFS and XOR-based component tracking efficiently.

困难
2331

计算布尔二叉树的值

Determine the boolean outcome of a full binary tree by evaluating leaf and internal nodes using depth-first traversal.

简单
2368

受限条件下可到达节点的数目

In the 'Reachable Nodes With Restrictions' problem, find the maximum reachable nodes from node 0 in a tree while avoidin…

中等
2385

感染二叉树需要的总时间

The problem asks to calculate the number of minutes for an infection to spread across all nodes in a binary tree startin…

中等
2415

反转二叉树的奇数层

Reverse the node values at each odd level in a perfect binary tree, preserving the even levels.

中等
2421

好路径的数目

Count all good paths in a tree by scanning node values and using hash maps to track valid connections efficiently.

困难
2440

创建价值相同的连通块

Maximize the number of components in a tree with equal sums by carefully deleting edges using divisor-based logic.

困难
2458

移除子树后的二叉树高度

Compute the height of a binary tree efficiently after removing subtrees, using traversal and precomputed node state trac…

困难
2467

树上最大得分和路径

Solve the 'Most Profitable Path in a Tree' problem using graph traversal and depth-first search techniques to maximize A…

中等
2471

逐层排序二叉树所需的最少操作数目

Determine the minimum number of swaps to sort each level of a binary tree using level-wise traversal efficiently.

中等
2476

二叉搜索树最近节点查询

Solve the problem of finding closest nodes in a Binary Search Tree for multiple queries, efficiently handling each query…

中等
2477

到达首都的最少油耗

Calculate the minimum fuel needed for all city representatives to reach the capital using DFS on a tree graph efficientl…

中等
2509

查询树中环的长度

Solve the problem of determining cycle lengths in a binary tree with added edges through queries.

困难
2538

最大价值和与最小价值和的差值

Compute the maximum difference between any path price sum in a tree using binary-tree traversal and state tracking effic…

困难
2581

统计可能的树根数目

Given a tree and a set of guesses, find how many nodes can be the root while satisfying the guess constraints.

困难
2583

二叉树中的第 K 大层和

Find the kth largest level sum in a binary tree using level-order traversal and sorting.

中等
2603

收集树中金币

The "Collect Coins in a Tree" problem requires traversing a tree to collect coins in the fewest steps while returning to…

困难
2641

二叉树的堂兄弟节点 II

Replace each node in a binary tree with the sum of all its cousins by carefully tracking depth and parent relationships.

中等
2646

最小化旅行的价格总和

Calculate the minimum total cost of multiple trips on a tree by selectively halving node prices using DFS frequency coun…

困难
2673

使二叉树所有路径值相等的最小代价

Minimize the cost increments required to equalize path costs in a binary tree from root to leaves.

中等
2791

树中可以形成回文的路径数

This problem asks you to count all node pairs in a tree whose path characters can be rearranged into a palindrome using …

困难
2846

边权重均等查询

Find the minimum number of operations to equalize edge weights in a tree between given pairs of nodes.

困难
2867

统计树中的合法路径数目

Count Valid Paths in a Tree involves finding paths with exactly one prime number in a tree of n nodes.

困难
2872

可以被 K 整除连通块的最大数目

Determine the maximum number of connected components in a tree where each component sum is divisible by k using DFS.

困难
2920

收集所有金币可获得的最大积分

Find the maximum points after collecting coins from all nodes of a tree using binary-tree traversal and state tracking.

困难
2925

在树上执行操作以后得到的最大分数

Solve Maximum Score After Applying Operations on a Tree by turning healthy-path constraints into subtree DP and forced-v…

中等
2973

树中每个节点放置的金币数目

Determine the exact number of coins to place on each tree node using subtree cost products and DFS tracking.

困难
3067

在带权树网络中统计可连接服务器对数目

This problem involves counting pairs of connectable servers in a weighted tree network using binary-tree traversal and D…

中等
3068

最大节点价值之和

Solve Find the Maximum Sum of Node Values by tracking XOR gain parity, not by simulating edge operations across the tree…

困难
3203

合并两棵树后的最小直径

Calculate the minimum diameter after merging two trees by strategically connecting nodes to minimize the longest path in…

困难
3241

标记所有节点需要的时间

Calculate the time taken to mark all nodes in a tree, starting from any node with time t=0.

困难
3249

统计好节点的数目

Determine how many nodes in a binary tree have all child subtrees of equal size using DFS traversal efficiently.

中等
3319

第 K 大的完美二叉子树的大小

Find the size of the kth largest perfect subtree in a binary tree using tree traversal and state tracking.

中等
3327

判断 DFS 字符串是否是回文串

Determine if strings formed by DFS traversal of a tree are palindromes using array scanning and hash lookups efficiently…

困难
3331

修改后子树的大小

Calculate the sizes of all subtrees after simultaneous parent changes using array scanning and hash-based counting effic…

中等
3367

移除边之后的权重最大和

Maximize the sum of edge weights in a tree after removals, using dynamic programming and tree traversal techniques.

困难
3372

连接两棵树后最大目标节点数目 I

Maximize the number of target nodes after connecting two trees using binary tree traversal and state tracking.

中等
3373

连接两棵树后最大目标节点数目 II

Maximize the number of target nodes after connecting two trees by analyzing their structure and target relationships.

困难
3425

最长特殊路径

Compute the longest downward path in a tree with unique node values using DFS, hash lookup, and careful array scanning.

困难
3486

最长特殊路径 II

Find the longest downward path in a tree where node values are mostly distinct, allowing one repeat, using array scannin…

困难
3515

带权树中的最短路径

Solve the Shortest Path in a Weighted Tree using binary-tree traversal and efficient state tracking for queries.

困难
3544

子树反转和

This problem involves calculating the maximum possible subtree inversion sum with dynamic programming and binary-tree tr…

困难
3553

包含要求路径的最小带权子图 II

Solve the Minimum Weighted Subgraph With the Required Paths II problem by leveraging binary-tree traversal and efficient…

困难
3558

给边赋权值的方案数 I

Calculate the number of valid edge weight assignments in a tree using DFS and binary-tree traversal with careful state t…

中等
3559

给边赋权值的方案数 II

This problem involves assigning edge weights in a tree and calculating the cost of paths based on these weights.

困难
3562

折扣价交易股票的最大利润

Solve the Maximum Profit from Trading Stocks with Discounts problem using binary-tree traversal and dynamic state tracki…

困难
3575

最大好子树分数

Find the maximum sum of values in a tree subtree without repeating any digit across selected nodes using DFS and bitmask…

困难
3585

树中找到带权中位节点

Given a weighted tree and queries, find the weighted median node for each path between two nodes using binary-tree trave…

困难
3590

第 K 小的路径异或和

This problem involves finding the kth smallest distinct XOR sum for nodes in a subtree of a tree structure using binary-…

困难
3593

使叶子路径成本相等的最小增量

Find the minimum number of increments needed to equalize leaf path scores in a tree with different node costs.

中等

关联高频模式

LeetCode 树题型题解:191题训练路线