We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I did it like this, with a third list for equals, in case there were integers repeated. The solutions in python all look so much cleaner than the C++/C/Java.
def quicksort(ar):
if len(ar) < 2:
return ar
lt, eq, rt = [], [], []
for item in ar:
if item < ar[0]:
lt.append(item)
elif item > ar[0]:
rt.append(item)
else:
eq.append(item)
sub = quicksort(lt) + eq + quicksort(rt)
print(' '.join([str(x) for x in sub]))
return(sub)
n = input().strip().split()
ar = [int(x) for x in input().strip().split()]
quicksort(ar)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Quicksort 2 - Sorting
You are viewing a single comment's thread. Return to all comments →
I did it like this, with a third list for equals, in case there were integers repeated. The solutions in python all look so much cleaner than the C++/C/Java.