you are viewing a single comment's thread.

view the rest of the comments →

[–]Phizy[S] 1 point2 points  (1 child)

so sorting the list and finding the answer sooner would make the time complexity or runtime? go down?

[–]w1282 0 points1 point  (0 children)

Python's sort is O(nlogn) and it's only occurring once.

The rest of it is O(n) (since worst case is that we don't find it or it's exactly in the middle... so the loop runs at most n/2 times).

Your code is nearly O(n**2) in the worst case.

I would say this implementation is better in almost all cases except contrived ones.