Created
April 30, 2021 23:19
-
-
Save cgopalan/710f532cedfa67f5f11daca91afc3080 to your computer and use it in GitHub Desktop.
Quicksort
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
from typing import List | |
def quicksort(ints: List[int]): | |
if len(ints) < 2 or len(set(ints)) == 1: | |
return ints | |
pivot = ints[0] | |
ints_less_than_pivot = [x for x in ints[1:] if x <= pivot] | |
ints_more_than_pivot = [x for x in ints[1:] if x > pivot] | |
return quicksort(ints_less_than_pivot) + [pivot] + quicksort(ints_more_than_pivot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment