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

Function find

javascript/0261-graph-valid-tree.js:127–136  ·  view source on GitHub ↗
(union, i, num = union[i])

Source from the content-addressed store, hash-verified

125const compress = (union, i, head) => (union[i] = head);
126
127const find = (union, i, num = union[i]) => {
128 const isEmpty = num === -1;
129 if (isEmpty) return i;
130
131 const head = find(union, num);
132
133 compress(union, i, head);
134
135 return union[i];
136};

Callers 2

validTreeFunction · 0.70
unionMethod · 0.50

Calls 1

compressFunction · 0.85

Tested by

no test coverage detected