面试场景
高频考察问题建模、边界条件与口头表达的清晰度。
常见误区
只背模板不解释为什么,容易在追问里失分。
练习策略
每轮练 3-5 题,固定复盘复杂度和可替代解法。
推荐练习顺序
二叉树的中序遍历
Binary Tree Inorder Traversal asks you to visit left subtree, node, then right subtree without losing position while mov…
不同的二叉搜索树 II
Generate all structurally unique BSTs with values 1 to n using backtracking and recursive tree construction techniques.
不同的二叉搜索树
Given n nodes, calculate the number of unique binary search trees (BSTs) that can be formed with values from 1 to n.
验证二叉搜索树
Validate Binary Search Tree problem checks if a binary tree satisfies BST properties using tree traversal and state trac…
恢复二叉搜索树
Recover a BST where two nodes are swapped by mistake using in-order traversal and careful state tracking to restore corr…
相同的树
Check whether two binary trees are identical by comparing structure and node values using DFS or BFS traversal strategie…
对称二叉树
Determine if a binary tree is symmetric by comparing left and right subtrees using DFS or BFS traversal techniques effic…
二叉树的层序遍历
Perform a level order traversal on a binary tree using BFS to return node values level by level.
二叉树的锯齿形层序遍历
Traverse a binary tree in zigzag level order, alternating directions at each depth using BFS and state tracking techniqu…
二叉树的最大深度
Find the maximum depth of a binary tree using traversal techniques to track the longest path from root to leaf.
从前序与中序遍历序列构造二叉树
Construct a binary tree using preorder and inorder traversal arrays, leveraging array scanning and hash table lookups.
从中序与后序遍历序列构造二叉树
Reconstruct a binary tree from given inorder and postorder arrays using array scanning and hash lookup to optimize recur…
二叉树的层序遍历 II
Return a bottom-up level order traversal of a binary tree, processing nodes left to right while tracking each level accu…
将有序数组转换为二叉搜索树
Pick the middle element as root at each step so the sorted array becomes a height-balanced BST with valid ordering.
有序链表转换二叉搜索树
Convert a sorted singly linked list into a height-balanced BST using pointer manipulation and divide-and-conquer recursi…
平衡二叉树
Determine if a binary tree is height-balanced using tree traversal and state tracking techniques.
二叉树的最小深度
Find the minimum depth of a binary tree, which is the shortest path from the root node to the nearest leaf node.
路径总和
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 …
路径总和 II
Find all root-to-leaf paths in a binary tree where the sum of node values equals a given target using DFS backtracking.
二叉树展开为链表
Flatten a binary tree into a right-skewed linked list by manipulating pointers following a pre-order traversal, handling…
填充每个节点的下一个右侧节点指针
Connect each node across every level by reusing established next links to traverse a perfect binary tree without extra q…
填充每个节点的下一个右侧节点指针 II
Populate each next pointer in a binary tree to its immediate right node, handling nulls and uneven levels efficiently us…
二叉树中的最大路径和
Calculate the maximum sum of any path in a binary tree by exploring all node sequences using DFS and dynamic programming…
求根节点到叶节点数字之和
Calculate the sum of all root-to-leaf numbers in a binary tree where each path represents a number.
二叉树的前序遍历
Perform a binary tree preorder traversal by visiting root nodes first, then left and right subtrees, tracking state iter…
二叉树的后序遍历
Solve Binary Tree Postorder Traversal using state tracking and binary-tree traversal techniques, focusing on Stack, Tree…
二叉搜索树迭代器
Implement an iterator for in-order traversal of a binary search tree (BST), maintaining traversal state with stack-based…
二叉树的右视图
The Binary Tree Right Side View problem asks you to return the visible nodes from the right side of a binary tree, trave…
完全二叉树的节点个数
Count Complete Tree Nodes efficiently by leveraging binary-tree traversal, exploiting completeness, and applying bit man…
翻转二叉树
Invert Binary Tree swaps every node's left and right children using tree traversal, with recursive DFS or iterative BFS …
二叉搜索树中第 K 小的元素
Find the kth smallest element in a BST by leveraging in-order traversal to efficiently track node order and count.
二叉搜索树的最近公共祖先
Find the lowest common ancestor (LCA) of two nodes in a binary search tree, using binary-tree traversal and state tracki…
二叉树的最近公共祖先
Identify the lowest common ancestor of two nodes in a binary tree using traversal and state tracking techniques efficien…
二叉树的所有路径
Find all root-to-leaf paths in a binary tree using DFS and backtracking, constructing strings for each complete path eff…
二叉树的序列化与反序列化
This problem asks to serialize and deserialize a binary tree, requiring an efficient approach to handle traversal and st…
验证二叉树的前序序列化
Determine if a given string correctly represents a binary tree preorder traversal using state tracking and slot counting…
打家劫舍 III
Maximize the loot by robbing non-adjacent houses in a binary tree structure using dynamic programming and DFS.
左叶子之和
Compute the total of all left leaves in a binary tree using precise traversal and state tracking techniques for correctn…
路径总和 III
Path Sum III challenges you to count paths in a binary tree that sum to a given target value with downward traversal.
序列化和反序列化二叉搜索树
Design an algorithm to serialize and deserialize a binary search tree with efficient traversal and state tracking.
删除二叉搜索树中的节点
Delete Node in a BST hinges on removing one target while preserving in-order ordering through carefully chosen subtree r…
二叉搜索树中的众数
Find Mode in Binary Search Tree asks to identify the most frequent element(s) in a BST using binary-tree traversal.
出现次数最多的子树元素和
Identify the most frequent subtree sum in a binary tree using DFS and hash table tracking for efficient state management…
找树左下角的值
Find the leftmost value in the last row of a binary tree using efficient traversal strategies.
在每个树行中找最大值
Find the largest value in each row of a binary tree using depth-first or breadth-first search techniques.
二叉搜索树的最小绝对差
Find the minimum absolute difference between values of any two nodes in a BST using tree traversal and careful state tra…
把二叉搜索树转换为累加树
Convert a BST into a Greater Tree by updating each node’s value with the sum of all greater values in the tree.
二叉树的直径
The Diameter of Binary Tree problem involves finding the longest path between any two nodes using tree traversal techniq…
二叉树的坡度
Calculate the sum of the binary tree's node tilts using tree traversal and state tracking.
另一棵树的子树
Determine if one binary tree is an exact subtree of another by comparing structure and node values recursively.
根据二叉树创建字符串
Given a binary tree, construct a string representation based on preorder traversal while adhering to specific formatting…
合并二叉树
Merge Two Binary Trees requires combining nodes by summing overlapping values while preserving non-null nodes from eithe…
在二叉树中增加一行
The problem requires adding a row of nodes to a binary tree at a specified depth.
二叉树的层平均值
Calculate the average value of nodes on each level of a binary tree using traversal and state tracking.
寻找重复的子树
Identify all duplicate subtrees in a binary tree by efficiently tracking structure and values with depth-first traversal…
两数之和 IV - 输入二叉搜索树
Determine if a binary search tree contains two nodes whose values sum to a target using efficient traversal and state tr…
最大二叉树
Construct a maximum binary tree by recursively selecting the largest element and dividing the array into left and right …
输出二叉树
Print Binary Tree requires arranging a binary tree into a visually structured matrix using precise traversal and positio…
二叉树最大宽度
Determine the maximum width of a binary tree by calculating the width of each level and considering the positions of the…
修剪二叉搜索树
Trim a Binary Search Tree by maintaining its structure while removing nodes outside a given range.
二叉树中第二小的节点
Find the second minimum node in a binary tree by traversing the tree and tracking state.
最长同值路径
Find the longest path in a binary tree where all nodes share the same value using depth-first search efficiently.
二叉搜索树中的搜索
Locate a target value in a binary search tree and return the subtree rooted at that node using efficient tree traversal …
二叉搜索树中的插入操作
Insert a value into a Binary Search Tree while maintaining the BST properties, focusing on tree traversal and state trac…
数据流中的第 K 大元素
Find the kth largest element in a dynamic stream using binary-tree traversal and efficient state tracking with a min-hea…
二叉搜索树节点最小距离
Find the minimum difference between values of two different nodes in a Binary Search Tree using tree traversal and state…
二叉树剪枝
Binary Tree Pruning removes subtrees not containing a 1, applying binary-tree traversal with state tracking.
二叉树中所有距离为 K 的结点
Find all nodes at distance K from a target node in a binary tree using various tree traversal techniques.
具有所有最深节点的最小子树
Find the smallest subtree that contains all the deepest nodes in a binary tree.
叶子相似的树
Determine if two binary trees have identical leaf sequences using efficient traversal and state tracking techniques.
根据前序和后序遍历构造二叉树
Reconstruct a binary tree from preorder and postorder traversals using array scanning and hash lookup.
所有可能的真二叉树
Generate all possible full binary trees with n nodes, focusing on dynamic programming and binary tree traversal.
递增顺序搜索树
Rearrange a binary search tree so all nodes follow increasing order with only right children using in-order traversal.
完全二叉树插入器
Implement a data structure to insert nodes into a complete binary tree while preserving its completeness efficiently.
二叉搜索树的范围和
Given a BST and a range, calculate the sum of all node values within that range.
翻转等价二叉树
Determine if two binary trees are flip equivalent by recursively swapping subtrees.
二叉树的完全性检验
Determine if a binary tree is complete by verifying its node structure and leftmost placement in the last level.
单值二叉树
Determine if a binary tree is uni-valued using traversal and state tracking techniques.
监控二叉树
Determine the minimum number of cameras required to monitor every node in a binary tree using efficient DFS and state tr…
翻转二叉树以匹配先序遍历
Determine the minimum set of nodes to flip in a binary tree so its pre-order traversal matches a given voyage sequence.
在二叉树中分配硬币
Minimize the number of moves needed to distribute coins in a binary tree so that each node has exactly one coin.
二叉树的垂序遍历
Perform a vertical order traversal of a binary tree, sorting nodes by their values within columns.
从叶结点开始的最小字符串
Determine the lexicographically smallest string from a leaf to root using binary-tree traversal and careful state tracki…
二叉树的堂兄弟节点
Determine if two nodes in a binary tree are cousins by leveraging binary-tree traversal and state tracking.
最大二叉树 II
The Maximum Binary Tree II problem requires building a binary tree by inserting a value into a maximum binary tree while…
前序遍历构造二叉搜索树
Construct a binary search tree directly from a preorder traversal array using stack-based state tracking efficiently.
从根到叶的二进制数之和
Calculate the sum of binary numbers from root to leaf paths in a binary tree.
节点与其祖先之间的最大差值
Find the maximum absolute difference between a node and its ancestor in a binary tree.
从先序遍历还原二叉树
Recover a binary tree from its preorder traversal string by tracking node depth and reconstructing child relationships e…
从二叉搜索树到更大和树
Convert a Binary Search Tree to a Greater Sum Tree by accumulating all larger node values using reverse in-order travers…
根到叶路径上的不足节点
Remove nodes in a binary tree whose all root-to-leaf paths sum to less than a given limit using DFS traversal and state …
二叉树寻路
The problem involves finding the path from the root to a node in a zigzag-labelled binary tree.
删点成林
Delete nodes from a binary tree using array scanning and hash lookup to return the remaining forest efficiently.
最深叶节点的最近公共祖先
Find the lowest common ancestor of the deepest leaves in a binary tree using efficient traversal and state tracking tech…
二叉树着色游戏
A two-player game where players color nodes in a binary tree, aiming to outmaneuver each other by choosing adjacent node…
最大层内元素和
Find the level of a binary tree where the sum of its nodes is maximal, with an emphasis on binary-tree traversal.
在受污染的二叉树中查找元素
Recover values in a contaminated binary tree and efficiently check for existence using traversal and state tracking tech…
层数最深叶子节点的和
Find the sum of the deepest leaves in a binary tree by using tree traversal and state tracking techniques.
两棵二叉搜索树中的所有元素
Merge elements from two binary search trees and return them sorted in ascending order.
祖父节点值为偶数的节点和
This problem involves calculating the sum of nodes with an even-valued grandparent in a binary tree.
删除给定值的叶子节点
In this problem, you need to delete all leaf nodes in a binary tree with a given target value, performing continuous del…
分裂二叉树的最大乘积
Maximize the product of sums of two subtrees formed by splitting a binary tree.
验证二叉树
Validate Binary Tree Nodes problem requires checking if a set of nodes forms a valid binary tree using graph traversal.
二叉树中的链表
Determine if a linked list is represented as a downward path in a binary tree using pointer traversal and recursive chec…
二叉树中的最长交错路径
Find the longest ZigZag path in a binary tree using depth-first search and dynamic programming for precise node state tr…
二叉搜索子树的最大键值和
Find the maximum sum of values from any Binary Search Tree (BST) subtree in a binary tree.
找出克隆二叉树中的相同节点
Find the corresponding node in a cloned binary tree using binary-tree traversal and state tracking.
将二叉搜索树变平衡
This problem requires balancing a binary search tree using in-order traversal and state tracking techniques.
统计二叉树中好节点的数目
Count Good Nodes in Binary Tree identifies nodes exceeding all previous values along their path using DFS traversal tech…
二叉树中的伪回文路径
Count all root-to-leaf paths in a binary tree that can be rearranged to form a palindrome using bitwise state tracking.
好叶子节点对的数量
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…
将子数组重新排序得到同一个二叉搜索树的方案数
Determine the number of ways to reorder an array to get the same binary search tree (BST) from its insertion order.
奇偶树
Determine if a binary tree meets Even-Odd rules by checking value parity and strict ordering at each level efficiently.
合并多棵二叉搜索树
This problem asks you to merge multiple BSTs into a single valid BST by performing a series of operations.
统计最高分的节点数目
Find the number of nodes with the highest score in a binary tree, based on subtree sizes and node removal.
从二叉树一个节点到另一个节点每一步的方向
Find the shortest path between two nodes in a binary tree and output the directions as a string of 'L', 'R', and 'U'.
根据描述创建二叉树
Build a binary tree from descriptions of parent-child relationships using array scanning and hash lookup.
判断根结点是否等于子结点之和
Check if a binary tree root value equals the sum of its immediate left and right child nodes efficiently.
统计值等于子树平均值的节点数
Given a binary tree, count nodes where the value equals the average of values in its subtree.
计算布尔二叉树的值
Determine the boolean outcome of a full binary tree by evaluating leaf and internal nodes using depth-first traversal.
感染二叉树需要的总时间
The problem asks to calculate the number of minutes for an infection to spread across all nodes in a binary tree startin…
反转二叉树的奇数层
Reverse the node values at each odd level in a perfect binary tree, preserving the even levels.
移除子树后的二叉树高度
Compute the height of a binary tree efficiently after removing subtrees, using traversal and precomputed node state trac…
逐层排序二叉树所需的最少操作数目
Determine the minimum number of swaps to sort each level of a binary tree using level-wise traversal efficiently.
二叉搜索树最近节点查询
Solve the problem of finding closest nodes in a Binary Search Tree for multiple queries, efficiently handling each query…
查询树中环的长度
Solve the problem of determining cycle lengths in a binary tree with added edges through queries.
二叉树中的第 K 大层和
Find the kth largest level sum in a binary tree using level-order traversal and sorting.
二叉树的堂兄弟节点 II
Replace each node in a binary tree with the sum of all its cousins by carefully tracking depth and parent relationships.
使二叉树所有路径值相等的最小代价
Minimize the cost increments required to equalize path costs in a binary tree from root to leaves.
第 K 大的完美二叉子树的大小
Find the size of the kth largest perfect subtree in a binary tree using tree traversal and state tracking.