Created
July 31, 2020 14:53
-
-
Save abinhho/51ede91bafc9a1ba5f0169f0b3c3485a to your computer and use it in GitHub Desktop.
This file contains 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
def count_numbers(sorted_list, less_than): | |
count = 0 | |
length = len(sorted_list) | |
if not length: | |
return 0 | |
if length == 1: | |
return count + 1 if sorted_list[0] < less_than else count | |
elif sorted_list[-1] < less_than: | |
return count + length | |
elif sorted_list[0] > less_than: | |
return count | |
half = length//2 | |
return count_numbers(sorted_list[:half], less_than) + count_numbers(sorted_list[half:], less_than) | |
sorted_list = [1, 2, 3, 3, 3, 4, 4 ,5, 5, 5, 5, 7] | |
print(count_numbers(sorted_list, 5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment