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

Method union

python/2709-greatest-common-divisor-traversal.py:12–22  ·  view source on GitHub ↗
(self, x, y)

Source from the content-addressed store, hash-verified

10 return self.par[x]
11
12 def union(self, x, y):
13 px, py = self.find(x), self.find(y)
14 if px == py:
15 return
16 if self.size[px] < self.size[py]:
17 self.par[px] = py
18 self.size[py] += self.size[px]
19 else:
20 self.par[py] = px
21 self.size[px] += self.size[py]
22 self.count -=1
23
24class Solution:
25 def canTraverseAllPairs(self, nums: List[int]) -> bool:

Callers 1

canTraverseAllPairsMethod · 0.95

Calls 1

findMethod · 0.95

Tested by

no test coverage detected