Fix bug in bucket_sort.py (#6005)

This commit is contained in:
eee555 2022-05-13 04:28:51 +08:00 committed by GitHub
parent 562cf31a9a
commit bbb88bb5c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,8 +54,8 @@ def bucket_sort(my_list: list) -> list:
bucket_count = int(max_value - min_value) + 1
buckets: list[list] = [[] for _ in range(bucket_count)]
for i in range(len(my_list)):
buckets[(int(my_list[i] - min_value) // bucket_count)].append(my_list[i])
for i in my_list:
buckets[int(i - min_value)].append(i)
return [v for bucket in buckets for v in sorted(bucket)]