Gary Lai

189. Rotate Array

189. Rotate Array 直觀的做法是按照題目所敘述的方式,每次把最後的數字放到最前面,在把剩餘的數字慢慢向後移。 假設有 n 個元素,有

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

276. Paint Fence

276. Paint Fence class Solution: def numWays(self, n: int,

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