NeetCode Comprehensive Algorithm Bank & Offline Handbook
Synchronized bilingual toggle with dual NeetCode & LeetCode problem numbering and direct links. Features step-by-step logic, benchmark Python3 code, complexity analysis, interview pitfalls, and standalone offline exports.
N-ary Tree Postorder Traversal (N 叉树的后序遍历)
Given the root of an N-ary tree, return its post-order traversal (children left to right, then the node) as a list of values. Cons...
Invert Binary Tree (翻转二叉树)
Given the root of a binary tree, invert it (swap every node's left and right children) and return its root. Constraints: the numbe...
Maximum Depth of Binary Tree (二叉树的最大深度)
Given the root of a binary tree, return its maximum depth: the number of nodes along the longest path from the root down to the fa...
Diameter of Binary Tree (二叉树的直径)
Given the root of a binary tree, return the length of its diameter: the number of edges on the longest path between any two nodes....
Balanced Binary Tree (平衡二叉树)
Given a binary tree, determine whether it is height-balanced: for every node, the heights of its two subtrees differ by at most 1....
Same Tree (相同的树)
Given the roots of two binary trees p and q, return true if they are structurally identical and every corresponding node has the s...
Subtree of Another Tree (另一棵树的子树)
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 v...
Convert Sorted Array to Binary Search Tree (将有序数组转换为二叉搜索树)
Given an integer array nums sorted in ascending order, convert it to a height-balanced binary search tree. Constraints: 1 <= nu...
Merge Two Binary Trees (合并二叉树)
You are given two binary trees root1 and root2. Merge them: where both nodes exist, the merged value is their sum; otherwise the e...
Path Sum (路径总和)
Given the root of a binary tree and an integer targetSum, return true if there is a root-to-leaf path whose values sum to the targ...
Range Sum of BST (二叉搜索树的范围和)
Given the root of a binary search tree and two integers low and high, return the sum of all values in the inclusive range [low, hi...
Leaf-Similar Trees (叶子相似的树)
Consider all the leaves of a binary tree, from left to right, forming a sequence. Two trees are leaf-similar if their leaf sequenc...
Evaluate Boolean Binary Tree (计算布尔二叉树的值)
You are given the root of a full binary tree where leaves have value 0 (false) or 1 (true), and internal nodes have value 2 (OR) o...
Closest Binary Search Tree Value (最接近的二叉搜索树值)
Given the root of a binary search tree and a floating-point target, return the value in the tree closest to the target. If several...
Binary Tree Vertical Order Traversal (二叉树的垂序遍历)
Given the root of a binary tree, return its vertical order traversal: a list of columns from leftmost to rightmost, where each col...
Binary Tree Longest Consecutive Sequence (二叉树最长连续序列)
Given the root of a binary tree, find the length of the longest consecutive path: a path where each node's value is exactly one gr...
Binary Tree Longest Consecutive Sequence II (二叉树最长连续序列 II)
Given the root of a binary tree, return the length of the longest consecutive path. Unlike the basic version, this path may be eit...
Count Univalue Subtrees (统计同值子树)
Given the root of a binary tree, return the number of uni-value subtrees: subtrees in which every node has the same value. Constra...
Maximum Average Subtree (子树的最大平均值)
Given the root of a binary tree, return the maximum average value of any subtree. A subtree is a node plus all its descendants, an...
Boundary of Binary Tree (二叉树的边界)
Given the root of a binary tree, return its boundary traversal: the root, then the left boundary (excluding leaves) top-down, then...
Find Leaves of Binary Tree (寻找二叉树的叶子节点)
Given the root of a binary tree, collect all its nodes level by level from the leaves upward: first all leaves are removed, then t...
Verify Preorder Sequence in Binary Search Tree (验证前序遍历序列二叉搜索树)
Given an array of unique integers preorder, return true if it is the pre-order traversal of some binary search tree. Constraints: ...
Two Sum BSTs (查找两棵二叉搜索树中的两数之和)
Given the roots of two binary search trees and an integer target, return true if there is a node in the first tree and a node in t...
Largest BST Subtree (最大 BST 子树)
Given the root of a binary tree, return the size of the largest subtree that is also a binary search tree. Constraints: the number...