Graph

841. Keys and Rooms

841. Keys and Rooms 透過拿到的鑰匙來造訪後面的房間,是圖形搜索的一種問題。 class Solution: def canVisitAllRooms(

1466. Reorder Routes to Make All Paths Lead to the City Zero

1466. Reorder Routes to Make All Paths Lead to the

1584. Min Cost to Connect All Points

這一題如果不用 UnionFind 的確會有點難做。 class UnionFind: def __init__(self, size): self.

UnionFind

Quick Find class UnionFind: def __init__(self, size): self.root

1091. Shortest Path in Binary Matrix

1091. Shortest Path in Binary Matrix 可以先練習這些題目 * 200. Number of

787. Cheapest Flights Within K Stops

787. Cheapest Flights Within K Stops 這一題的考點 1. 在 BFS

399. Evaluate Division

399. Evaluate Division class Solution: def calcEquation(self, equations: List[

1202. Smallest String With Swaps

1202. Smallest String With Swaps 這個題目難在要怎麼想到使用 Graph 的實作來做。 題目給定的 pairs

1101. The Earliest Moment When Everyone Become Friends

1101. The Earliest Moment When Everyone Become Friends 這個題目是我認為很好的一道面試題,因為題目的情景很貼近日常生活,

797. All Paths From Source to Target

797. All Paths From Source to Target class Solution: def