题库chevron_right分类chevron_right
hub

141 道题目
简单: 3中等: 66困难: 72

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

面试场景

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

常见误区

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

练习策略

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

推荐练习顺序

#题目难度
133

克隆图

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

中等
207

课程表

Determine if all courses can be completed by analyzing prerequisite dependencies using indegree tracking and topological…

中等
210

课程表 II

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

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

困难
399

除法求值

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

中等
547

省份数量

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

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

困难
743

网络延迟时间

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

中等
753

破解保险箱

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

困难
765

情侣牵手

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

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

中等
834

树中距离之和

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

困难
841

钥匙和房间

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

中等
847

访问所有节点的最短路径

Solve the Shortest Path Visiting All Nodes problem by exploring dynamic programming, bit manipulation, and breadth-first…

困难
851

喧闹和富有

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

中等
882

细分图中的可到达节点

The Reachable Nodes In Subdivided Graph problem requires efficiently finding the reachable nodes using graph traversal a…

困难
886

可能的二分法

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

中等
913

猫和老鼠

Determine the outcome of a two-player Cat and Mouse game on a graph using topological ordering and memoized dynamic prog…

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

困难
947

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

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

中等
990

等式方程的可满足性

Determine if it's possible to assign values to variables such that all equations are satisfied based on equality and ine…

中等
997

找到小镇的法官

Find the Town Judge is an easy LeetCode problem that challenges you to identify a town judge from trust relationships us…

简单
1042

不邻接植花

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

中等
1129

颜色交替的最短路径

Solve the shortest path problem with alternating edge colors using graph traversal and BFS.

中等
1192

查找集群内的关键连接

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

困难
1203

项目管理

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

困难
1298

你能从盒子里获得的最大糖果数

Collect maximum candies from boxes by exploring initially available boxes and using keys to unlock additional ones effic…

困难
1311

获取你好友已观看的视频

Find videos watched by friends up to a given level and return them sorted by frequency and alphabetically.

中等
1319

连通网络的操作次数

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

中等
1334

阈值距离内邻居最少的城市

Find the city with the fewest neighbors within a given threshold distance using dynamic programming.

中等
1361

验证二叉树

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

中等
1368

使网格图至少有一条有效路径的最小代价

Determine the minimum cost to create at least one valid path from the top-left to bottom-right in a directional grid.

困难
1377

T 秒后青蛙的位置

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

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

中等
1489

找到最小生成树里的关键边和伪关键边

Identify critical and pseudo-critical edges in a weighted graph's minimum spanning tree using Union Find efficiently.

困难
1494

并行课程 II

Determine the minimum semesters to complete all courses with prerequisites using state transition dynamic programming an…

困难
1514

概率最大的路径

Find the path with the highest success probability in a graph from a start node to an end node, using edge probabilities…

中等
1557

可以到达所有点的最少点数目

Identify the minimum set of vertices in a directed acyclic graph from which all nodes are reachable efficiently using gr…

中等
1579

保证图可完全遍历

Maximize the number of edges that can be removed while keeping the graph fully traversable for both Alice and Bob.

困难
1584

连接所有点的最小费用

Min Cost to Connect All Points asks for the minimum cost to connect all points on a 2D plane, using manhattan distances …

中等
1591

奇怪的打印机 II

Solve Strange Printer II by building color dependencies from bounding rectangles and checking whether a topological orde…

困难
1615

最大网络秩

Calculate the maximum network rank of two cities by analyzing all city pairs using a graph-driven solution strategy effi…

中等
1632

矩阵转换后的排名

Compute a unique rank matrix using graph indegree with topological ordering, ensuring each element reflects its relative…

困难
1697

检查边长度限制的路径是否存在

Solve the problem of checking if there exists a path between two nodes under edge length constraints using efficient tec…

困难
1719

重构一棵树的方案数

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

困难
1728

猫和老鼠 II

Cat and Mouse II requires determining if the mouse can reach food before being caught using graph and topological orderi…

困难
1761

一个图中连通三元组的最小度数

Find the minimum degree of a connected trio in a graph using enumeration over nodes and edges.

困难
1782

统计点对的数目

Given a graph with nodes and edges, count pairs of nodes where the degree sum exceeds a given threshold for each query.

困难
1786

从第一个节点出发到最后一个节点的受限路径数

Solve the problem of finding the number of restricted paths in a weighted undirected graph, leveraging graph algorithms …

中等
1791

找出星型图的中心节点

Find the center node of a star graph, where one node connects to all others.

简单
1857

有向图中最大颜色值

Compute the maximum color frequency along any valid path in a directed graph using topological ordering and dynamic prog…

困难
1916

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

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

困难
1928

规定时间内到达终点的最小花费

Minimize the travel cost in a graph while adhering to a time constraint using state transition dynamic programming.

困难
1971

寻找图中是否存在路径

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

简单
1976

到达目的地的方案数

Find the number of ways to travel from intersection 0 to n - 1 in the shortest time, using a graph-based approach.

中等
2039

网络空闲的时刻

Calculate the time when the network becomes idle, factoring in message resending and the BFS traversal method.

中等
2045

到达目的地的第二短时间

Find the second minimum time to reach a destination using BFS while accounting for traffic signal delays in a graph trav…

困难
2050

并行课程 III

Solve Parallel Courses III by finding the minimum number of months to complete all courses using graph-based topological…

困难
2065

最大化一张图中的路径价值

Calculate the maximum path quality in a graph using backtracking and pruning to optimize node visits within time limits …

困难
2076

处理含限制条件的好友请求

Determine which friend requests can be accepted without violating direct or indirect restrictions using union-find logic…

困难
2092

找出知晓秘密的所有专家

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

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

中等
2115

从给定原材料中找到所有可以做出的菜

Determine all recipes you can prepare given initial supplies and ingredient dependencies, leveraging array scanning and …

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

中等
2203

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

Find the minimum weighted subgraph that connects three specified nodes in a directed graph with constraints.

困难
2242

节点序列的最大得分

Find the maximum score of a valid node sequence in an undirected graph with given node scores and edges.

困难
2246

相邻字符不同的最长路径

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

困难
2285

道路的最大总重要性

Assign unique values to cities to maximize the total importance of all roads using greedy selection based on city connec…

中等
2290

到达角落需要移除障碍物的最小数目

Find the minimum obstacles to remove in a 2D grid to reach the bottom-right corner using BFS graph traversal techniques.

困难
2316

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

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

中等
2328

网格图中递增路径的数目

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

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

中等
2374

边积分最高的节点

Determine the node with the highest edge score in a graph using hash table aggregation and careful index tracking.

中等
2392

给定条件下构造矩阵

Solve the matrix-building problem by using graph indegree and topological sorting to satisfy given row and column constr…

困难
2421

好路径的数目

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

困难
2467

树上最大得分和路径

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

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

困难
2497

图中最大星和

Find the maximum star sum in a graph with specific node values and edges, using greedy algorithms to select the optimal …

中等
2508

添加边使所有节点度数都为偶数

Determine if it's possible to add at most two edges to make all node degrees even in an undirected graph.

困难
2577

在网格图中访问一个格子的最少时间

Compute the fastest path in a grid where each cell has a minimum time requirement using BFS and priority queue technique…

困难
2603

收集树中金币

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

困难
2608

图中的最短环

Find the shortest cycle in a bi-directional graph using BFS for optimal traversal.

困难
2642

设计可以求最短路径的图类

Implement a dynamic weighted directed graph with efficient shortest path queries and edge additions in real time.

困难
2646

最小化旅行的价格总和

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

困难
2662

前往目标的最小代价

Find the minimum cost path between two points, using special roads or direct moves in a 2D space.

中等
2685

统计完全连通分量的数量

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

中等
2699

修改图中的边权

Modify Graph Edge Weights is a graph problem where you adjust edge weights to match a target shortest path distance.

困难
2846

边权重均等查询

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

困难
2858

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

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

困难
2876

有向图访问计数

Count Visited Nodes in a Directed Graph uses dynamic programming to solve graph traversal and node visitation counting e…

困难
2924

找到冠军 II

Identify the strongest team in a tournament DAG using graph-driven logic, ensuring correct handling of in-degree zero ch…

中等
2959

关闭分部的可行集合数目

Calculate all valid sets of branch closures while keeping remaining branches within maxDistance using bitmask and graph …

困难
2976

转换字符串的最小成本 I

This problem asks to calculate the minimum cost to convert a string from source to target using specific character trans…

中等
2977

转换字符串的最小成本 II

Compute the minimum cost to transform source into target using substring replacements with given costs efficiently using…

困难
3015

按距离统计房屋对数目 I

Determine the number of house pairs at each street distance using graph traversal and breadth-first search efficiently.

中等
3017

按距离统计房屋对数目 II

Count the Number of Houses at a Certain Distance II is a graph problem that requires efficient pair counting with an add…

困难
3108

带权图里旅途的最小代价

Find the minimum cost walk in a weighted graph using array and bit manipulation techniques for efficient path calculatio…

困难
3112

访问消失节点的最少时间

Determine the minimum time to visit each node in a disappearing-node graph using arrays, graphs, and priority queues eff…

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

困难
3241

标记所有节点需要的时间

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

困难
3243

新增道路查询后的最短距离 I

Solve shortest paths dynamically in a growing graph using BFS, updating distances efficiently after each road addition q…

中等
3244

新增道路查询后的最短距离 II

The problem involves calculating the shortest path from city 0 to city n-1 after each road addition, leveraging greedy c…

困难
3286

穿越网格图的安全路径

Determine if you can safely traverse a binary grid from top-left to bottom-right using limited health points.

中等
3310

移除可疑的方法

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

中等
3311

构造符合图结构的二维矩阵

This problem challenges you to construct a 2D grid from an undirected graph using a given set of edges.

困难
3341

到达最后一个房间的最少时间 I

Find Minimum Time to Reach Last Room I challenges you to determine the minimum time to travel in a dungeon with a grid l…

中等
3342

到达最后一个房间的最少时间 II

Calculate the minimum time to reach the last room in a grid with alternating move times using array and graph patterns.

中等
3377

使两个整数相等的数位操作

Transform n into m using allowed digit operations without creating primes, applying math and graph strategies efficientl…

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

中等
3435

最短公共超序列的字母出现频率

Compute all unique shortest common supersequences of given words using graph indegree tracking and topological ordering …

困难
3493

属性图

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

中等
3528

单位转换 I

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

中等
3530

有向无环图中合法拓扑排序的最大利润

Solve the Maximum Profit from Valid Topological Order in DAG problem using graph indegree and topological sorting with d…

困难
3532

针对图的路径存在性查询 I

Determine if paths exist between nodes using array scanning and hash lookups for efficient component checks in graphs.

中等
3534

针对图的路径存在性查询 II

Solve path existence queries in a graph using binary search on the answer space, focusing on sorted nodes and maximum di…

困难
3543

K 条边路径的最大边权和

Determine the maximum sum of edge weights for a k-edge path in a DAG using state transition dynamic programming efficien…

中等
3547

图中边值的最大和

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

困难
3594

所有人渡河所需的最短时间

Find the minimum time to transport individuals across a river with dynamic environmental conditions and boat capacity.

困难
3600

升级后最大生成树稳定性

Maximizing the stability of a spanning tree with upgrades requires careful optimization of edge strengths using binary s…

困难
3604

有向图中到达终点的最少时间

The problem involves finding the minimum time to reach the destination in a directed graph with time-dependent edges.

中等
3607

电网维护

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

中等
3608

包含 K 个连通分量需要的最小时间

Find the minimum time to remove edges such that a graph with n nodes has at least k connected components.

中等
3613

最小化连通分量的最大成本

Minimize Maximum Component Cost leverages binary search over edge weights to optimize the cost of graph components after…

中等
3615

图中的最长回文路径

Find the longest path in a graph that forms a palindrome using state transition dynamic programming and bitmask techniqu…

困难
3620

恢复网络路径

Find the maximum recovery cost of valid paths in a directed acyclic graph where some nodes are offline.

困难

关联高频模式

LeetCode 图题型题解:141题训练路线