题库chevron_right分类chevron_right深度优先搜索
arrow_downward

深度优先搜索

252 道题目
简单: 36中等: 148困难: 68

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

面试场景

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

常见误区

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

练习策略

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

推荐练习顺序

#题目难度
79

单词搜索

Solve Word Search with backtracking by exploring adjacent cells to match a target word in a grid.

中等
94

二叉树的中序遍历

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

简单
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…

简单
104

二叉树的最大深度

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

简单
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.

中等
130

被围绕的区域

Transform the matrix in-place by marking regions surrounded by 'X' as 'X', while keeping border-adjacent 'O's intact.

中等
133

克隆图

Clone Graph involves cloning a graph using DFS, focusing on graph traversal and neighbor management using hash tables.

中等
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…

简单
199

二叉树的右视图

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

中等
200

岛屿数量

Count the number of distinct islands in a binary grid using array traversal combined with depth-first search exploration…

中等
210

课程表 II

Solve the 'Course Schedule II' problem using graph indegree and topological ordering, utilizing DFS or BFS to find the c…

中等
211

添加与搜索单词 - 数据结构设计

Build a WordDictionary supporting dynamic word addition and search with wildcard matching efficiently using Trie and DFS…

中等
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…

困难
310

最小高度树

Identify all roots of a tree that produce minimum height using graph indegree analysis and topological trimming.

中等
329

矩阵中的最长递增路径

Find the length of the longest increasing path in a matrix with given movement constraints using graph techniques.

困难
332

重新安排行程

Reconstruct Itinerary requires building a valid travel route using all tickets once, starting from JFK with lexical orde…

困难
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.

中等
365

水壶问题

Determine if two jugs with given capacities can measure an exact target amount using math and DFS strategies efficiently…

中等
385

迷你语法分析器

Deserialize a nested list string using stack-based state management, handling integers and nested lists with depth-first…

中等
386

字典序排数

Generate all numbers from 1 to n in lexicographical order using a depth-first search pattern optimized with trie logic f…

中等
388

文件的最长绝对路径

Find the length of the longest absolute file path in a filesystem string using stack-based depth tracking efficiently.

中等
399

除法求值

Compute the results of division queries from given equations using graph traversal and depth-first search efficiently.

中等
404

左叶子之和

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

简单
417

太平洋大西洋水流问题

Find all cells on an island where water can flow to both the Pacific and Atlantic oceans using DFS or BFS.

中等
419

棋盘上的战舰

Count the number of non-overlapping battleships on a 2D board using array traversal and depth-first search patterns effi…

中等
430

扁平化多级双向链表

Flatten a multilevel doubly linked list by correctly updating next, prev, and child pointers to create a single-level se…

中等
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.

中等
463

岛屿的周长

Determine the perimeter of an island in a grid of land and water cells using DFS or BFS.

简单
472

连接词

Find concatenated words by using dynamic programming and depth-first search to identify valid words made of other words …

困难
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.

中等
514

自由之路

Determine the minimum rotations and button presses to spell a keyword on a circular dial using state transition dynamic …

困难
515

在每个树行中找最大值

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

中等
529

扫雷游戏

Solve the Minesweeper game by updating revealed squares and handling clicks with Depth-First Search and Array manipulati…

中等
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…

简单
547

省份数量

Solve Number of Provinces by scanning the adjacency matrix and launching DFS once per unvisited city component.

中等
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.

简单
565

数组嵌套

Find the longest nested set in a permutation array using a depth-first traversal, handling cycles efficiently for medium…

中等
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…

简单
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.

简单
672

灯泡开关 Ⅱ

Compute all unique bulb configurations after a fixed number of presses using math and bit manipulation efficiently.

中等
676

实现一个魔法字典

Design a Magic Dictionary to allow searching with one-character modifications, using Hash Table and String techniques.

中等
684

冗余连接

Identify and remove the redundant edge that causes a cycle in a graph starting as a tree.

中等
685

冗余连接 II

Find and remove the redundant connection in a directed graph that was originally a rooted tree.

困难
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…

中等
695

岛屿的最大面积

Find the largest connected land area in a binary grid using array traversal and depth-first search efficiently.

中等
721

账户合并

Merge accounts by connecting emails and returning each user's sorted email list using array scanning and hash lookup eff…

中等
733

图像渲染

Flood Fill is an array and DFS problem where you change connected pixels to a target color efficiently using recursion o…

简单
743

网络延迟时间

Find the minimum time for a signal to travel to all nodes in a directed graph or determine if it's impossible.

中等
749

隔离病毒

Contain Virus involves using array-based Depth-First Search to contain viral spread by building walls around infected re…

困难
753

破解保险箱

The Cracking the Safe problem involves finding the shortest password sequence to unlock a safe using graph traversal and…

困难
756

金字塔转换矩阵

The Pyramid Transition Matrix problem requires determining whether a pyramid can be formed with given blocks and valid p…

中等
765

情侣牵手

This problem requires arranging couples sitting apart in a row with the minimum number of swaps using graph traversal an…

困难
778

水位上升的泳池中游泳

Solve the problem of swimming through a grid of rising water with a binary search on the valid answer space.

困难
783

二叉搜索树节点最小距离

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

简单
785

判断二分图

Determine whether an undirected graph can be split into two independent sets using DFS, BFS, or Union Find patterns.

中等
787

K 站中转内最便宜的航班

Find the cheapest flight from a source to a destination with at most K stops using graph traversal techniques efficientl…

中等
797

所有可能的路径

Find all paths in a directed acyclic graph (DAG) from source to target using depth-first search and backtracking.

中等
802

找到最终的安全状态

Solve the problem of finding eventual safe states in a directed graph using depth-first search and topological sorting.

中等
814

二叉树剪枝

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

中等
827

最大人工岛

Calculate the largest island size by converting at most one zero in a binary grid using array and DFS techniques efficie…

困难
834

树中距离之和

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

困难
839

相似字符串组

Determine the number of connected groups of similar strings by swapping at most two letters using array scanning and has…

困难
841

钥匙和房间

Determine if all rooms can be visited given keys distributed across a set of interconnected locked rooms using graph tra…

中等
851

喧闹和富有

Determine the quietest person richer than each individual using graph indegree analysis and topological ordering techniq…

中等
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.

简单
886

可能的二分法

Determine if a group of n people with mutual dislikes can be split into two non-conflicting groups using graph traversal…

中等
897

递增顺序搜索树

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

简单
924

尽量减少恶意软件的传播

Identify which single infected node to remove to minimize total malware spread in a connected network graph efficiently.

困难
928

尽量减少恶意软件的传播 II

Minimize Malware Spread II asks to minimize the spread of malware in a network of nodes by removing one infected node.

困难
934

最短的桥

Find the minimum flips to connect two separate islands in a binary matrix using Array and DFS techniques efficiently.

中等
938

二叉搜索树的范围和

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

简单
947

移除最多的同行或同列石头

Maximize the number of stones removed from a 2D plane using graph traversal and DFS.

中等
951

翻转等价二叉树

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

中等
959

由斜杠划分区域

Determine the number of regions in a grid divided by slashes using array scanning and union-find techniques efficiently.

中等
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.

简单
1020

飞地的数量

This problem involves finding the number of land cells that cannot reach the boundary in a grid using DFS and array mani…

中等
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…

困难
1034

边界着色

Given a grid and a starting cell, color all border cells of the connected component using DFS while preserving interior …

中等
1036

逃离大迷宫

The 'Escape a Large Maze' problem involves navigating a massive grid with blocked squares and finding if a target can be…

困难
1038

从二叉搜索树到更大和树

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

中等
1042

不邻接植花

In this problem, you are tasked with planting flowers in gardens with specific constraints based on graph traversal prin…

中等
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 …

中等
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.

中等
1192

查找集群内的关键连接

Find critical connections in a network of servers, ensuring efficient traversal using depth-first search and Tarjan's al…

困难
1202

交换字符串中的元素

Find the lexicographically smallest string by swapping characters in given pairs of indices.

中等
1203

项目管理

Sort items into groups while respecting dependencies using graph indegree tracking and topological ordering patterns eff…

困难
1233

删除子文件夹

Remove sub-folders in a filesystem by filtering out folders nested inside other folders.

中等
1254

统计封闭岛屿的数目

Count the number of closed islands in a 2D grid using array traversal and depth-first search efficiently.

中等
1261

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

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

中等
1267

统计参与通信的服务器

Count Servers that Communicate involves identifying servers in a grid that can communicate based on row or column connec…

中等
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.

中等
1306

跳跃游戏 III

Jump Game III challenges you to determine if you can reach any zero in an array using jumps defined by array values, tes…

中等
1315

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

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

中等
1319

连通网络的操作次数

Determine the minimum number of operations required to connect all computers in a network with a limited number of cable…

中等
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.

中等
1391

检查网格中是否存在有效路径

Check if there is a valid path from the upper-left to the bottom-right corner of a grid using depth-first search.

中等
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.

中等
1462

课程表 IV

Determine if one course is a prerequisite of another using graph indegree tracking and topological ordering efficiently.

中等
1466

重新规划路线

Reorder Routes to Make All Paths Lead to the City Zero involves reversing the direction of roads in a tree to ensure all…

中等
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…

中等
1559

二维网格图中探测环

Detect cycles in a 2D character grid using DFS while carefully tracking parent cells to avoid invalid revisits.

中等
1568

使陆地分离的最少天数

Find the minimum number of days to disconnect an island in a grid using depth-first search.

困难
1600

王位继承顺序

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

中等
1625

执行操作后字典序最小的字符串

Optimize a string through rotations and additions to get the lexicographically smallest possible result using string man…

中等
1631

最小体力消耗路径

Find the minimum effort required to travel from the top-left to the bottom-right of a grid, considering height differenc…

中等
1722

执行交换操作后的最小汉明距离

Solve Minimize Hamming Distance After Swap Operations by grouping swappable indices and matching value counts inside eac…

中等
1743

从相邻元素对还原数组

Restore the Array From Adjacent Pairs reconstructs a sequence using adjacent element pairs. Efficient hash lookups and a…

中等
1766

互质树

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

困难
1905

统计子岛屿

Identify and count all islands in grid2 that are fully contained within islands of grid1 using DFS traversal efficiently…

中等
1932

合并多棵二叉搜索树

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

困难
1938

查询最大基因差

Find the maximum genetic difference along paths in a tree using array scanning and hash lookups with XOR calculations.

困难
1970

你能穿过矩阵的最后一天

Find the last day to walk from top to bottom in a flooded matrix by using binary search and graph traversal techniques.

困难
1971

寻找图中是否存在路径

Determine if a valid path exists between two vertices in a bi-directional graph using traversal techniques.

简单
1992

找到所有的农场组

Identify all rectangular farmland groups in a binary matrix using array traversal and depth-first search efficiently.

中等
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.

中等
2092

找出知晓秘密的所有专家

Find all people who receive a secret through meetings using graph traversal with depth-first search efficiently and corr…

困难
2096

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

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

中等
2097

合法重新排列数对

Given pairs of numbers, find a valid arrangement where each pair follows a specific condition.

困难
2101

引爆最多的炸弹

Determine the maximum number of bombs that can be detonated by leveraging chain reactions using graph traversal and DFS …

中等
2127

参加会议的最多员工数

Determine the maximum employees to invite based on favorite adjacency constraints using graph indegree and topological o…

困难
2192

有向无环图中一个节点的所有祖先

Solve the All Ancestors of a Node in a Directed Acyclic Graph problem using graph traversal techniques like BFS, DFS, an…

中等
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.

中等
2316

统计无向图中无法互相到达点对数

Calculate the total number of node pairs in an undirected graph that cannot reach each other using DFS, BFS, or Union Fi…

中等
2322

从树中删除边的最小分数

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

困难
2328

网格图中递增路径的数目

Solve Number of Increasing Paths in a Grid by turning cell comparisons into a DAG and counting paths with topological DP…

困难
2331

计算布尔二叉树的值

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

简单
2359

找到离给定两个节点最近的节点

Find the node that minimizes the maximum distance to two given nodes in a directed graph with one outgoing edge per node…

中等
2360

图中的最长环

The problem asks to find the longest cycle in a directed graph with specific edge constraints.

困难
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.

中等
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…

中等
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…

中等
2492

两个城市间路径的最小分数

Find the minimum distance in a path connecting two cities using graph traversal strategies efficiently.

中等
2493

将节点分成尽可能多的组

Determine the maximum number of groups nodes can form in a graph using depth-first traversal without violating edge conn…

困难
2538

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

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

困难
2556

二进制矩阵中翻转最多一次使路径不连通

Determine if a single cell flip can disconnect a path from the top-left to bottom-right in a binary matrix efficiently u…

中等
2581

统计可能的树根数目

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

困难
2596

检查骑士巡视方案

Validate a knight's movement configuration on an n x n chessboard to check if it forms a valid Knight's Tour.

中等
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…

困难
2658

网格图中鱼的最大数目

Maximize the number of fish that can be caught by performing DFS on an optimal starting point in a grid.

中等
2685

统计完全连通分量的数量

Determine the number of complete connected components in an undirected graph using efficient traversal techniques and gr…

中等
2791

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

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

困难
2858

可以到达每一个节点的最少边反转次数

This problem requires solving a graph traversal with edge reversals to ensure every node is reachable in a tree-like str…

困难
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…

中等
3123

最短路径中的边

Use two Dijkstra runs to mark exactly which edges can appear on at least one shortest path from 0 to n - 1.

困难
3203

合并两棵树后的最小直径

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

困难
3235

判断矩形的两个角落是否可达

Determine if there is a valid path from the bottom-left to top-right of a rectangle while avoiding circles.

困难
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.

中等
3310

移除可疑的方法

Remove suspicious methods in a project that are invoked directly or indirectly from a buggy method using graph traversal…

中等
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.

困难
3376

破解锁的最少时间 I

Solve the Minimum Time to Break Locks I problem using state transition dynamic programming to minimize the time to break…

中等
3387

两天自由外汇交易后的最大货币数

Compute the maximum currency amount after two days using graph traversal and depth-first search for optimal conversions.

中等
3419

图的最大边权的最小值

Minimize the maximum edge weight in a graph after removing certain edges while ensuring node reachability.

中等
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…

困难
3493

属性图

Find the number of connected components in an undirected graph formed by properties arrays, using array scanning and has…

中等
3515

带权树中的最短路径

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

困难
3528

单位转换 I

Solve the unit conversion problem by using graph traversal to compute equivalent unit amounts.

中等
3544

子树反转和

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

困难
3547

图中边值的最大和

Maximize the sum of edge values in a connected graph by assigning unique node values and optimizing edge products.

困难
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.

中等
3607

电网维护

Determine which power stations remain connected after maintenance using array scanning and hash lookups to track compone…

中等
3619

总价值可以被 K 整除的岛屿数目

Count the number of islands in a grid where the sum of each island's values is divisible by a given integer k.

中等

关联高频模式

LeetCode 深度优先搜索题型题解:252题训练路线