Fix index off by 1

This commit is contained in:
Danila Fedorin 2019-09-27 14:35:28 -07:00
parent 5c43ffb602
commit 022533dc4a

View File

@ -7,9 +7,9 @@ def qselect(i, xs):
left = [x for x in xs if x < pivot] left = [x for x in xs if x < pivot]
right = [x for x in xs if x >= pivot] right = [x for x in xs if x >= pivot]
if i > len(left): if i > len(left) + 1:
return qselect(i - len(left) - 1, right) return qselect(i - len(left) - 1, right)
elif i == len(left): elif i == len(left) + 1:
return pivot return pivot
else: else:
return qselect(i, left) return qselect(i, left)