2.5 Union Find/ Trie Tree
并查集:集合查询合并 支持O(1)find/O(1)union
Union Find
templete
class UnionFind:
self.father = []
def self.find(x):
if self.father[x] == x:
return x
self.father[x] = find(self.father[x])
return self.father[x]
def self.union(a,b):
root_a = self.find(a)
root_b = self.find(b)
if root_a != root_b:
father[root_a] = root_b
application(graph)
Number of Connected Components in an Undirected Graph
Number of Islands
Number of Islands II
Number of Distinct Islands
* Graph Valid Tree
* Surrounded Regions
Trie Tree
1.考点:
2. Hash vs Trie
Implement Trie
Design Add and Search Words Data Structure
Word Search II
Word Square
Last updated