Enough memory: You can use the idea of a quick sort, which is an O (n), and the algorithm thought is as follows:
• Randomly select an element to place the element smaller than it on the left, and the element larger than it on the right
• If it happens to be in the middle digit position, then it is the median and can be returned directly
• If the number is less than half of it, then the median must be on the left half, recursively to the left.
• Otherwise, the median must be on the right half, based on the number of elements on the left half, the median is the right half, and then recursively to the right half.
Low memory Condition:
Method: Divided method
Idea: An important clue is that these numbers are all integers. Integers have a range, 32-bit system is [ -2^32, 2^32-1], there is a range we can do two points on this range, and then find how many number of ⼩ in mid, more than mid, and then recursion, and based on the quicksort idea of the K-big method similar to
Method Two: The idea of the barrel method: The big to small, divide all the numbers into each cell, map each number to the corresponding interval, count the number of each interval, count the intervals, see where the median grumble is, if it's small enough, use a memory based algorithm, or continue dividing
by one Piece