Skip to content

Commit 7634cf0

Browse files
authored
Fix mypy errors at gale_shapely_bigraph (TheAlgorithms#4568)
1 parent 407c979 commit 7634cf0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

graphs/gale_shapley_bigraph.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from __future__ import annotations
22

33

4-
def stable_matching(donor_pref: list[int], recipient_pref: list[int]) -> list[int]:
4+
def stable_matching(
5+
donor_pref: list[list[int]], recipient_pref: list[list[int]]
6+
) -> list[int]:
57
"""
68
Finds the stable match in any bipartite graph, i.e a pairing where no 2 objects
79
prefer each other over their partner. The function accepts the preferences of
@@ -19,18 +21,21 @@ def stable_matching(donor_pref: list[int], recipient_pref: list[int]) -> list[in
1921
[1, 2, 3, 0]
2022
"""
2123
assert len(donor_pref) == len(recipient_pref)
24+
2225
n = len(donor_pref)
2326
unmatched_donors = list(range(n))
2427
donor_record = [-1] * n # who the donor has donated to
2528
rec_record = [-1] * n # who the recipient has received from
2629
num_donations = [0] * n
30+
2731
while unmatched_donors:
2832
donor = unmatched_donors[0]
2933
donor_preference = donor_pref[donor]
3034
recipient = donor_preference[num_donations[donor]]
3135
num_donations[donor] += 1
3236
rec_preference = recipient_pref[recipient]
3337
prev_donor = rec_record[recipient]
38+
3439
if prev_donor != -1:
3540
if rec_preference.index(prev_donor) > rec_preference.index(donor):
3641
rec_record[recipient] = donor

0 commit comments

Comments
 (0)