LeetCode图 常见的题型以及要注意的点

图的题目一直是pain in the ass,虽然总体来说只有两个算法来解决这个问题:DFS和BFS 常用的数据结构有:hashmap
此外 要注意某一些能用并查集去做的题目。
而且也要注意那些看上去并不属于图的题目 也很有可能可以用图去做。

由于图的题目变化多端,所以如何对图的题目进行整理分类?
大多数题目,用BFS也可以 用DFS也可以,只是有的用DFS好写一些 有的用BFS好写一些
DFS也好 BFS也好 都是通过遍历所有的节点来得到我们想要得到的东西。
所以图的题目就很简单了?无非是DFS BFS?
当然不是。图的问题 难点在于最开始的时候如何读懂那一大长串题目 并如何用DFS/BFS来解决问题(有个清晰的思路 这个是最难的)
而且在实现过程中 会出现许许多多的corner case, 让人一度崩溃到绝望。
代码很长,但是一定要注意分块标注此块功能 避免忘记 这样debug的时候也好办。

下面的问题 虽然不都是高频题目 但是归类非常好

    1. Satisfiability of Equality Equations - union find
    1. Find the Town Judge
    1. Clone Graph
    1. Find the City With the Smallest Number of Neighbors at a Threshold Distance
    1. Count Servers that Communicate
    1. Possible Bipartition
    1. Course Schedule
    1. Course Schedule IV
    1. Reorder Routes to Make All Paths Lead to the City Zero
    1. Minimum Moves to Reach Target with Rotations
    1. Smallest String With Swaps
    1. Cheapest Flights Within K Stops
    1. Reconstruct Itinerary
    1. Number of Nodes in the Sub-Tree With the Same Label
    1. Generate Random Point in a Circle
    1. Detect Cycles in 2D Grid
    1. Minimum Height Trees
    1. Word Ladder
    1. Friend Circles
    1. Min Cost to Connect All Points
    1. Redundant Connection
    1. Redundant Connection II
    1. Network Delay Time
    1. Accounts Merge
    1. Loud and Rich
    1. Evaluate Division
    1. Count Subtrees With Max Distance Between Cities
    1. Minimum Number of Flips to Convert Binary Matrix to Zero Matrix
    1. Shortest Path in a Grid with Obstacles Elimination
    1. Maximum Candies You Can Get from Boxes
    1. Jump Game IV
    1. Check if There is a Valid Path in a Grid
    1. As Far from Land as Possible
    1. Shortest Path in Binary Matrix
    1. Coloring A Border
    1. Number of Enclaves
    1. Max Area of Island
    1. Rotting Oranges
    1. Flood Fill
    1. Lexicographically Smallest String After Applying Operations
    1. Graph Connectivity With Threshold
    1. Most Stones Removed with Same Row or Column
    1. Minimum Jumps to Reach Home
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值