Write a program to find 100 largest numbers out of an array of 1 billion numbers

前端 未结 30 2202
深忆病人
深忆病人 2020-11-29 14:04

I recently attended an interview where I was asked \"write a program to find 100 largest numbers out of an array of 1 billion numbers.\"

I was only able to give a br

30条回答
  •  我在风中等你
    2020-11-29 15:03

    i did my own code,not sure if its what the "interviewer" it's looking

    private static final int MAX=100;
     PriorityQueue queue = new PriorityQueue<>(MAX);
            queue.add(array[0]);
            for (int i=1;i=MAX)
                    {
                        queue.poll();
                    }
                    queue.add(array[i]);
    
                }
    
            }
    

提交回复
热议问题