Skip to content

Commit 5d02103

Browse files
authored
1 parent 66a528b commit 5d02103

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

data_structures/disjoint_set/disjoint_set.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ def union_set(x, y):
2626
disjoint set tree will be more flat.
2727
"""
2828
x, y = find_set(x), find_set(y)
29-
if x.rank > y.rank:
29+
if x == y:
30+
return
31+
32+
elif x.rank > y.rank:
3033
y.parent = x
3134
else:
3235
x.parent = y

0 commit comments

Comments
 (0)