Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
joesinghh authored Sep 24, 2021
1 parent 66a528b commit 5d02103
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion data_structures/disjoint_set/disjoint_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def union_set(x, y):
disjoint set tree will be more flat.
"""
x, y = find_set(x), find_set(y)
if x.rank > y.rank:
if x == y:
return

elif x.rank > y.rank:
y.parent = x
else:
x.parent = y
Expand Down

0 comments on commit 5d02103

Please sign in to comment.