Created
March 2, 2022 16:25
-
-
Save hvuhsg/a0eea706ad46a311f50194d829c258aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numbers = [5, 8, 6, 3, 9, 9, 2, 4, 7, 7, 6] | |
def sort(arr): | |
bucket = [0] * 100 | |
for number in arr: | |
bucket[number] += 1 | |
sorted_arr = [] | |
for i, num in enumerate(bucket): | |
sorted_arr.extend([i] * num) | |
return sorted_arr | |
print(sort(numbers)) # -> [2, 3, 4, 5, 6, 6, 7, 7, 8, 9, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment