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

Method __connect

python/0261-graph-valid-tree.py:48–58  ·  view source on GitHub ↗
(self, n: int, m: int)

Source from the content-addressed store, hash-verified

46 return n
47
48 def __connect(self, n: int, m: int) -> None:
49 pn = self.__find(n)
50 pm = self.__find(m)
51 if pn == pm:
52 return
53 if self.heights.get(pn, 1) > self.heights.get(pm, 1):
54 self.parents[pn] = pm
55 else:
56 self.parents[pm] = pn
57 self.heights[pm] = self.heights.get(pn, 1) + 1
58 self.components -= 1
59
60 def valid_tree(self, n: int, edges: List[List[int]]) -> bool:
61 # init here as not sure that ctor will be re-invoked in different tests

Callers 1

valid_treeMethod · 0.95

Calls 2

__findMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected