Union-Find
Union Find
·4 分鐘
演算法
Union-Find
Union Find 介紹
LeetCode 3493: Properties Graph
·1 分鐘
LeetCode
Medium
Graph
Dfs
Union-Find
Hash-Map
LeetCode 3493 解題筆記:先把每列轉成 set,兩兩比較交集大小建邊,再數連通塊
LeetCode 695: Max Area of Island
·1 分鐘
LeetCode
Medium
Array
Depth-First-Search
Breadth-First-Search
Union-Find
LeetCode 695 解題筆記:每遇到一個沒走過的 1 就 DFS 整座島,數格子數,取最大值;格子是整數 1,不是字串
LeetCode 128: Longest Consecutive Sequence
·1 分鐘
LeetCode
Medium
Array
Hash-Table
Union-Find
LeetCode 128 解題筆記:放進 set,只從「x - 1 不在 set 裡」的數開始往上數,每個數最多被看兩次,O(n)