MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / union

Method union

python/0684-redundant-connection.py:14–25  ·  view source on GitHub ↗
(n1, n2)

Source from the content-addressed store, hash-verified

12
13 # return False if already unioned
14 def union(n1, n2):
15 p1, p2 = find(n1), find(n2)
16
17 if p1 == p2:
18 return False
19 if rank[p1] > rank[p2]:
20 par[p2] = p1
21 rank[p1] += rank[p2]
22 else:
23 par[p1] = p2
24 rank[p2] += rank[p1]
25 return True
26
27 for n1, n2 in edges:
28 if not union(n1, n2):

Callers

nothing calls this directly

Calls 1

findFunction · 0.50

Tested by

no test coverage detected