| given an array of integers ( n... | |||||||
|
30 Day Risk-Free Guarantee:
100% money back if you're unsatisfied. Book (308 Pages):
![]() Video (One Hour):
![]() Resume Review (24 - 48hr)
All Products / Services
|
|||||||
Above solution is wrong.
However, There is a O(n) solution to this problem.
Refer to: http://en.wikipedia.org/wiki/Selection_algorithm
there is a o(n) solution. Set 2 varialble Median-left and Median-right to represent the medians of this integer array(when the length is even,there is 2 medians),then read from left to right from the integer array,initialize the medians and then only compare the left integers inside the array with these 2 medians, and replace them if nessary.At last the median will be found