Skip to content

Commit 6d8ba23

Browse files
authored
Update find_union_tree.py
h field is needed only in the root of the tree and can be removed from other nodes
1 parent 698d4c6 commit 6d8ba23

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

find_union_tree.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ def union(self, other: 'FindUnionTree') -> None:
4444
other_root.parent = self_root
4545
if self_root.h == other_root.h:
4646
self_root.h += 1
47+
del other_root.h
4748
else:
4849
self_root.parent = other_root
50+
del self_root.h
4951

5052

5153
if __name__ == "__main__": # demo program:

0 commit comments

Comments
 (0)